A REST API JSON request is an HTTP request whose body carries data formatted as JSON, so a server can read structured fields instead of a long string of text. You send it by calling the right URL with the right method and a header that says Content-Type: application/json, then the server replies, usually with JSON too. A minimal working example looks like this:
POST /api/v1/notes HTTP/1.1
Host: example.com
Content-Type: application/json
Authorization: Bearer YOUR_TOKEN
{
"title": "Reading list",
"items": ["Dune", "Piranesi"],
"archived": false
}
Every part of that message has a job. The method says what to do, the path says where, the headers describe the data, and the body carries the JSON itself. Get one of these wrong and the server usually tells you, but not always in words you expect, so it helps to know what each piece is for.
What Do GET, POST, PUT, PATCH and DELETE Expect From a JSON Request?
The method decides whether a body is expected at all. This is the first place people go wrong, because sending JSON where the server does not look for it produces confusing results.
- GET asks for data. It should not carry a request body. Filters and options go in the query string, such as
/notes?limit=20&sort=created. - POST creates something or triggers an action. It expects a JSON body describing the new thing.
- PUT replaces a resource. The body should contain the complete record, not just the changed fields.
- PATCH updates part of a resource. The body holds only the fields you want to change.
- DELETE removes a resource. It usually needs no body, only the path and headers.
The practical consequence is that a GET with a JSON body may be silently ignored or rejected, depending on the server. If a search or filter is not working, check that you are not hiding parameters in a body that nobody reads.
For PUT, a partial body is a common trap. If a record has a title, a body and a status, sending only the status through PUT can erase the other two fields on servers that treat PUT as a full replacement. Use PATCH when the intent is a small change, and use PUT only when you have the whole record to hand.
Which Headers and Status Codes Does a JSON Request Need?
Two headers do most of the work. Content-Type: application/json tells the server how to read the body. Accept: application/json tells the server what you can read in the reply. Both are worth sending on every call with a body. If the API needs a key or token, that goes in an Authorization header, never in the URL where logs can capture it.
The status code is how the server reports the outcome without you reading prose. These are the ones that come up most often:
- 200 and 201: success, with 201 meaning something was created.
- 400: the server could not parse or accept the JSON you sent, often a syntax error or a missing required field.
- 401 and 403: you are not authenticated, or you are authenticated but not allowed.
- 404: the path or the resource does not exist.
- 405: the path exists but does not accept that method.
- 415: the server does not accept the content type, usually a missing or wrong
Content-Typeheader. - 422: the JSON parsed but the values failed validation, such as a text field left empty.
- 429: too many requests; slow down and retry later.
When a call fails, read the response body before changing anything. Many APIs return a JSON error object with a message and a field name, which saves a lot of guessing. Labels and error shapes can differ between APIs, so check the API's own documentation for the exact field names.
Why Does a JSON Request Return a 415 or 400 Error?
A 415 nearly always means the server did not see a JSON content type. Some tools send form data by default, so setting the header explicitly fixes it. A 400 is more often about the body itself: a trailing comma, single quotes instead of double quotes, an unquoted field name, or a value sent as text when a number was expected. A quick check is to paste the body into any JSON validator before sending it again.
JSON Request or Form-Encoded Request: What Is the Difference?
The usual comparison is between JSON and form encoding, because both are ways to pack fields into a request body for the same kind of API call.
- JSON (
application/json) carries types directly. A number stays a number, a boolean stays true or false, and lists and nested objects keep their shape. It handles structure well, which is why most modern APIs use it for create and update calls. - Form encoding (
application/x-www-form-urlencoded) turns every field into text joined with ampersands, such astitle=Reading+list&archived=false. Everything arrives as a string, so the server has to convert it. It is the format a plain HTML form produces.
The same data in each format shows the difference plainly. JSON keeps a real list of two items; form encoding has to repeat or number the field to express the same list, and the server has to know that convention. When the body contains nested data, JSON is the simpler choice. When you are posting a simple set of text fields from a form, form encoding still works and some older APIs expect it.
A related format, multipart form data, is the one to use for file uploads. It can carry binary content alongside text fields, which plain JSON cannot do without encoding the file as text first.
How Can You Build and Send a JSON Request Safely?
Build the request in small steps rather than all at once. Each step gives you a clear signal if something is off.
- Read the API reference for the exact path, method and required fields. Note which fields are mandatory and what type each one takes.
- Write the JSON body and check it is valid: double quotes around keys and text, no trailing commas, numbers without quotes.
- Decide the method. Use POST to create, PATCH for a partial change, PUT only for a full replacement.
- Set the headers: content type, accept, and the authorization value the API asks for.
- Send the request and read the status code first, then the response body.
- If it fails, change one thing at a time and resend, so you know which change fixed it.
Test against a sandbox or a test account when one is available. Sending create calls to live data is the quickest way to make a mess you have to clean up by hand.
Before you send anything, check what is in the body. JSON requests often carry names, addresses, notes or tokens, and those end up in logs and error reports. Keep secrets in headers rather than in the body where possible, and avoid pasting real customer data into a public tool for testing.
How Do You Read a JSON Response and Check It Worked?
A successful response body is the server's copy of the data, often including fields you did not send, such as an ID and a creation timestamp. Read those fields rather than assuming them. If you need the new ID for your next call, take it from the response instead of guessing a value.
Check three things after any write. The status code should match the action: 201 for a create, 200 for an update. The returned object should show the values you sent, unchanged. And a follow-up GET of the same path should return the same data, which confirms the change was saved rather than just echoed back.
If the response is empty on a delete, that is normal; 204 means success with nothing to read. If the response looks like the old record after a PATCH, a field name probably did not match the API's spelling, and the server ignored it quietly. Compare your body against the reference field by field.
What Belongs in the JSON Body and What Belongs in the URL?
Use the URL for identifying which resource you mean and for options that change how it is returned. Use the body for the data you are sending to be stored or processed. Filtering by status, ordering results and setting a page size all belong in the query string. A record's title, description and settings belong in the body.
One misconception is worth correcting here. JSON is a text format for moving data, not a security measure. A server still has to validate every field it receives, because a well-formed JSON request can carry hostile values. If you maintain the receiving side, never trust a field just because it parsed cleanly.
Keep your JSON small and predictable. Send only the fields the API documents, use consistent naming, and send lists as lists rather than as joined strings. A request that says exactly what it means is far easier to debug at the moment something returns a 400.