First let be give you some background and then I'll proceed to specific answer.
You're using Express so to parse the request body you'll use the body-parser. See:
Maybe it's best to look at some examples that you can test by sending requests using both JSON and data in the format coming from HTML forms.
Example request using form encoding:
curl -X POST localhost:4443 \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'a=X&b=Y'
(this is a single command that can be put in one line without the backslashes)
Example request using JSON encoding:
curl -X POST localhost:4443 \
-H 'Content-type: application/json' \
-d '{"a":"X","b":"Y"}'
(again this is also a single command - put on multiple lines for readability)
Now, the server code that can respond to those requests:
This is a server that accepts JSON:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.post('/', (req, res) => {
console.log(req.body);
res.json({ ok: true });
});
app.listen(4443, () => console.log('Listening on http://localhost:4443/'));
This is a server that accepts form data:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/', (req, res) => {
console.log(req.body);
res.json({ ok: true });
});
app.listen(4443, () => console.log('Listening on http://localhost:4443/'));
This is a server that accepts both:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/', (req, res) => {
console.log(req.body);
res.json({ ok: true });
});
app.listen(4443, () => console.log('Listening on http://localhost:4443/'));
As you can see it is trivial to support both styles and you don't need to choose only one of them.
Now, to your specific question:
So my question is which method is better when building a API is it accepting JSON request or normal request, which one is better if my API is made for other developers?
As a developer I personally prefer using JSON but I can understand the need to use the form encoding if it's needed. With Express it's very easy to support both at the same time so you don't have to choose just one.
But if you want to choose only one for some reason then talk to your developers. Those are the consumers of your API so they are the only people who can tell you what's "better".