Adding a request body
Send text, JSON, form fields or files with a request.
Overview
The Body tab holds the content a request sends. Choose a body type from the menu at the top of the tab, and Relay shows an editor for that type and sets a matching Content-Type header when it sends, unless you add your own in the Headers tab.
| Body type | Sends | Default Content-Type |
|---|---|---|
| None | No body. | None |
| Text | Text you write. | The type you enter, text/plain to start with |
| JSON | JSON you write. | application/json |
| GraphQL | A GraphQL operation and its variables, as JSON. | application/json |
| Form URL-Encoded | Fields encoded as name=value pairs. | application/x-www-form-urlencoded |
| Multipart Form | Text fields and files. | multipart/form-data with a boundary |
Every body type accepts variables, such as {{userId}}, in its text, fields and values. For GraphQL, see Sending GraphQL queries.
Choose a body type
- In the request editor, click Body, or press Command-5.
- Click the menu at the top of the tab and choose a body type.
GET, HEAD and TRACE requests can't have a body, so choosing a body type for one of them changes its method to POST. For more information, see Setting the method and URL.
When you switch to another type, Relay keeps the body you leave. Switch back and it's restored, so you can try a request with form fields and with JSON without retyping either one. Only the selected type is sent. Switching from GraphQL to JSON when there's no JSON body yet fills the JSON editor with the GraphQL request's JSON payload.
Send text
Choose Text, then write the body in the editor. Enter the body's media type, such as application/xml or text/csv, in the Content-Type field above the editor.
Send JSON
Choose JSON, then write the body in the editor. To indent the JSON and sort its keys, click the Beautify JSON button above the editor. Relay sends the text exactly as it appears, so tokens such as {{count}} can stand in for numbers or objects:
{
"name": "{{userName}}",
"limit": {{pageSize}}
}Send form fields
Choose Form URL-Encoded, then click Add Field and enter each field's name and value. Relay percent-encodes the names and values and joins them with &.
Deselect a field's checkbox to leave it out without deleting it. To delete a field, click the Remove button (–) at the end of its row. A field without a name isn't sent.
Send files and fields as multipart form data
Choose Multipart Form, then click Add Part for each part and enter its name.
Each part is text or a file. To change a part's type, click the icon at the start of its value and choose Text or File:
- Text: Enter the value.
- File: Click Choose… and select the file, or enter its path. Relay reads the file each time you send, so the request always sends the file's current contents. The part is sent with the file's name and, unless an imported request gave it another, the
application/octet-streamcontent type.
If Relay can't read a file when you send, the request doesn't go out and the status shows which file and part it couldn't read. Choose the file again to fix it.
See Also
- Setting the method and URL: Choose a standard or custom HTTP method and build the URL and its query parameters.
- Adding headers: Send headers with a request and control which ones are included.
- Sending GraphQL queries: Write GraphQL operations with schema-aware completion and send them with variables.
- Using variables: Insert values into requests with
{{name}}tokens and see where each value comes from.