REST Web Services

Best Practices to follow while writing REST WS :


Form encoding while making POST requests : When you make a POST request, you have to encode the data that forms the body of the request in some way.

HTML forms provide three methods of encoding.

  • application/x-www-form-urlencoded (the default)
  • multipart/form-data
  • text/plain

Use multipart/form-data if the request contains a File upload and it should be used in combination with the INPUT element, type=”file”.
Use application/x-www-form-urlencoded otherwise, which is the default if you omit enctype header in the request.
NEVER use text/plain as it only used if you want to debug the payload you are sending as part of HTTP request.

URL Encode Query params : When sending requests to REST API from POSTMAN, make sure you URL-Encode the query parameters part of the request.

CORS : Cross origin Resource Sharing : (
When a request is made from browser to fetch data from an API, Origin header is always sent along with the request. Origin denotes the source of the request. This origin is parsed and verified at API to determine if it can respond with data.

For Http requests that can cause side effects on server data like PUT, DELETE, browser sends an OPTIONS request(Preflight request) before sending the actual request. When API gets the OPTIONS request, it then responds with details like allowed methods, allowed headers, etc – only then browser makes the actual PUT/DELETE requests to API.

Support infinite scrolling via REST API :




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s