Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

November Discount Launch 2022 – Top
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

November Discount Launch 2022 – TEMP TOP (NPI)
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

1. Overview

Postman provides multiple ways to interact with an API or server request with different types of body parameters. These represent different ways of sending data through an HTTP request to the API.

In this tutorial, we'll explore the differences between using form-data, x-www-form-urlencoded, and raw for our request body.

2. form-data

Form-data represents the data sent from website forms to APIs as part of multipart/form-data. The form-data option in Postman simulates filling out a form on a website and submitting it. We can edit the form data and let it set the different key/value pairs by transforming the key-value editor in the data.

This can also be used for attaching files to the keys as well. However, we should note that using HTML5 means that the files aren't in any history or collections. Therefore, we must select the file again at the time of sending the request body. Also, uploading multiple files with their content type isn't supported by Postman.

Note that Postman will persist the file paths with subsequent use, i.e., when we repeatedly make an API call that sends the same file onto the server. This helps in running collections with multiple requests to upload files.

Let's see what using form-data looks like in Postman:

form-data

3. x-www-form-urlencoded

The URL-encoded data sends encoded data to the server, and uses the same encoding as that of the URL parameters. To use it, we need to select the x-www-form-urlencoded tab in the body of the request. We need to enter the key-value pairs for sending the request body to the server, and Postman will encode the desired data before sending it. Postman encodes both the key and the value.

Note that it can't be used for encoding files, so we need to manually do it ourselves. However, it can only encode the request body data or the URL parameters.

This is also known as the default content type. All the forms submitted with this content type follow the below encoding pattern:

  • The control names and values are escaped. All space characters will be replaced by the ‘+' symbol, and reserved characters follow the RFC 17.38 notations.
  • An equal symbol, ‘=', is used for separating the key and value, and the key/value pairs use ‘&' to be separated from each other.

Let's take a look at the x-www-form-urlencoded tab in Postman:

form-urlencoded-tab

4. raw

As the name suggests, raw data can consist of anything. Postman doesn't touch the raw string or make any type of alterations to it. The string added into the raw editor goes unmodified, except for replacing the defined environment variables. This editor lets us set different formatting styles supported by the Postman, along with the correct header that's required to be sent with the raw body. The following types are supported:

  • Text
  • Javascript
  • JSON
  • HTML
  • XML

We can also set these Content-Types manually into our request body:

request-body

5. Difference BETWEEN form-data, x-www-form-urlencoded and raw

We can use the different forms of data content types as defined by the W3C committee. They've defined multiple formats for sending the data over the Network Layer. These include form-data, x-www-form-urlencoded, and raw data. By default, we can send data in simple text/ASCII format by using the x-www-form-urlencoded format.

However, using the x-www-form-urlencoded data type has a data limit. As such, we can use form-data for sending large binary or non-ASCII text to the server.

The raw data type sends any plain text or JSON to the server, as the name suggests. It supports multiple content types, and Postman will send the raw data without any modifications, unlike with the other data types.

We can use the raw data type to send any type of data in the request body. This also includes sending the Javascript functions that could be executed on the server side. We can send the scripts under the Javascript option. The raw data type also supports markup languages, such as HTML and XML. This can be helpful when there's no logic at the front end and we need to consume the whole HTML/XML page.

6. Conclusion

In this article, we examined a few of the request body data types supported by Postman.

We also outlined the differences between form-data, x-www-form-urlencoded and raw in Postman. However, we only gained a basic understanding of the requests. If you want to understand these request body types more deeply, you can explore the Postman online documentation.

November Discount Launch 2022 – Bottom
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Generic footer banner
Comments are closed on this article!