Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 30 ยท Sending Requests

Methods and request bodies

Use GET, POST, PUT, PATCH and DELETE in Postman, and choose the right body type: raw JSON, form-data, x-www-form-urlencoded, binary or GraphQL.

A GET request only asks for data. As soon as you want to create, change or delete something, you need other methods, and usually a body: the data that travels with the request. Postman's Body tab offers several formats, and choosing the wrong one is one of the most common reasons a request fails with a puzzling 400 or 415.

This lesson explains the five everyday methods and each body type. The real Postman screens are described in text, because they cannot run here. The runnable examples are stand-ins: a small local HTTP server that echoes back what it received, so you can see exactly how each body type looks on the wire. The server is deliberately simple. Real APIs add validation, authentication and databases.

Five everyday methods

GET Read data. No body.
POST Create something new.
PUT Replace a whole resource.
PATCH Change only some fields.
1 / 2

Choosing the method

Select the method from the drop-down at the left of the URL bar. The conventions from HTTP and REST in ten minutes apply:

  • GET /todos/1 reads a todo. It has no body.
  • POST /todos creates a todo from the body.
  • PUT /todos/1 replaces todo 1 with exactly the body you send. Fields you leave out are usually removed or reset.
  • PATCH /todos/1 changes only the fields you send and leaves the others alone.
  • DELETE /todos/1 removes it. A successful delete often answers 204 No Content.

The difference between PUT and PATCH surprises many people, so the first stand-in shows it. The little server stores one todo, and the client sends a PUT, then a PATCH, then a DELETE.

Node.js PUT replaces, PATCH merges, DELETE removes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

After the PUT, the tag field is gone, because a replacement contains only what you sent. The PATCH changed done and kept the title. The DELETE answered 204 with an empty body, and the final GET returns 404. In a real API, the exact behavior of PUT and PATCH is up to the developers, so test it: it is a classic place for bugs.

The Body tab

When you pick a method that allows a body, open the Body tab. It shows a row of radio buttons for the body type:

  • none: no body (the default for GET).
  • form-data: key/value pairs sent as multipart/form-data; the only mode that can upload files together with text fields.
  • x-www-form-urlencoded: key/value pairs sent like a classic HTML form.
  • raw: free text, with a drop-down to choose Text, JavaScript, JSON, HTML or XML.
  • binary: a single file sent as the entire body.
  • GraphQL: a query pane and a variables pane for GraphQL APIs.

The body type decides the Content-Type header, and that header tells the server how to read the bytes. If you pick raw but leave the drop-down on Text while the API expects JSON, many servers will refuse the request or misread it. Choosing JSON in the raw drop-down sets Content-Type: application/json for you. You can check this in the Headers tab, where Postman shows its automatic headers when you reveal the hidden ones.

Pick the body to match the API

raw JSON The default for most modern APIs.
form-data Files plus text fields.
urlencoded Simple form fields, a=1&b=2.
binary One file as the whole body.
1 / 2

raw JSON

The most common choice for modern APIs. You type the JSON yourself:

JSON
{
  "title": "Write tests",
  "done": false
}

JSON is strict: keys need double quotes, there are no trailing commas, and no comments. A single stray comma makes the server answer 400.

form-data and x-www-form-urlencoded

Both send key/value pairs, but in different encodings. x-www-form-urlencoded puts the pairs in one line, like a query string (name=Ada&role=admin). form-data (multipart/form-data) splits them into separate parts, each with its own headers, which is how files are uploaded. For file fields, hover over the key cell and switch its type from Text to File.

binary

The body is a single file sent as-is. This suits APIs that accept raw image or document uploads, usually with a specific Content-Type such as application/octet-stream or image/png.

GraphQL

GraphQL APIs usually take a single POST whose JSON body contains a query string and optional variables. Postman's GraphQL mode gives you two panes so you do not have to escape the query yourself. More on that in Testing GraphQL, WebSocket and gRPC.

Seeing the bodies on the wire

The next stand-in is an echo server. It looks at the Content-Type of each request and reports how it interpreted the body. The client then sends five different body types, just like switching the radio buttons in Postman.

Node.js Five body types, as the server sees them

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Look at how the same server reads each body differently. The JSON body is parsed into an object, the form body becomes name/value fields, the binary body is just five bytes shown in hexadecimal, and the GraphQL request is ordinary JSON with a query and variables. If a client sent JSON but forgot the right Content-Type, this server would treat it as plain text, which is exactly the kind of mismatch that causes errors in real life.

Multipart form-data and files

multipart/form-data is the most complicated format, because the body is divided into parts separated by a random boundary string. The Content-Type header carries the boundary so the server knows where parts start and end. In Postman you never see this: you fill in rows. The stand-in below sends two text fields and one small "file" using the built-in FormData, then prints the raw body with the boundary replaced by a readable word.

Node.js What multipart/form-data looks like

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Each part starts with a boundary line, then its own headers (Content-Disposition with the field name, plus a filename and Content-Type for the file), then a blank line, then the value. The server splits on the boundary. Postman builds exactly this structure from your form-data rows.

If an upload fails, open the Postman Console and look at the request that was actually sent. The Content-Type header and the body structure are often the clue. Do not type a Content-Type header yourself for form-data: Postman must generate it, because it contains the boundary.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A todo has the fields id, title, done and tag. You send PUT with only title and done. What do you usually expect afterwards?

    PUT sends a complete replacement. Fields you leave out are normally dropped. Use PATCH to change only some fields.
  2. 2. Which Body type should you pick to upload a file together with text fields?

    form-data is multipart, so it can carry files and text fields as separate parts.
  3. 3. What does the Content-Type header tell the server?

    The server decides how to parse the body from Content-Type. A wrong value can lead to 400 or 415 responses.
  4. 4. In Postman's GraphQL body mode, what is actually sent over HTTP?

    GraphQL over HTTP is normally a JSON POST with a query string and variables. The two panes just make it easier to edit.
  5. 5. Why should you not type your own Content-Type header for form-data requests?

    The boundary string must match the one used inside the body, so letting Postman create the header avoids a mismatch.

Summary

  • Use GET to read, POST to create, PUT to replace, PATCH to change part of a resource and DELETE to remove it.
  • The Body tab chooses the format: none, form-data, x-www-form-urlencoded, raw, binary or GraphQL.
  • The body type decides the Content-Type header, which tells the server how to parse the bytes.
  • Raw JSON must be strict JSON: double-quoted keys, no trailing commas.
  • form-data is multipart (boundaries, parts, files); urlencoded is a one-line a=1&b=2.
  • GraphQL requests are JSON POSTs with a query and variables.
  • The echo server here is a stand-in; real servers add validation and security, and may treat PUT and PATCH differently.

Next: Query params, headers and cookies.