Where to put parameters in a REST API?

Where to put parameters in a REST API?

Locators such as “id=5” or “action=refresh” or “page=2” would make sense to have as a URL path, such as mysite.com/article/5/page=2 where partly you know what each part is supposed to mean (the basics such as article and 5 obviously mean get me the data of type article with id 5) and additional parameters are specified as part of the URI.

Can you pass multiple post parameters to web API controller?

ASP.NET Web API brings many new features and many advantages over the older Microsoft AJAX and REST APIs, but realize that some things like passing multiple strongly typed object parameters will work a bit differently. It’s not insurmountable]

When to use POST / PUT / DELETE in rest?

In other words, if your API action changes the server state, REST advises us to use POST/PUT/DELETE, but not GET. User agents usually understand that doing multiple POSTs is bad and will warn against it, because the intent of POST is to alter server state (eg. pay for goods at checkout), and you probably don’t want to do that twice!

How to create a post with query parameters?

The POST above has a query parameter referring to an existing resource. The body parameter defines the new resource to be created. I prefer this to having the path of the end-point to point directly to the already-existing recourse, like so: POST /user_settings/4 {

Can you put an object into a request parameter?

Technically, you could also put an object into an URL parameter (as JSON, XML or whatever), but that is unusual, so I would avoid it if possible. 1) Strictly speaking, you can use a body with a GET request, but this is unusual and generally not recommended; see e.g. HTTP GET with request body.

Do you have to send parameters as URL parameters?

If the parameters are very large, you may have to use POST to get around length limitations, but usually this is not a problem (most software supports quite long URLs), and safe requests should use GET to allow optimizations such as caching and prefetching. If you use GET, you must send your parameters as URL parameters 1).

What’s the best way to post parameters in JSON?

Best practice is to POST the parameters as an object. This avoids the URL length limit and other problems with query strings. If you send multiple parameters in JSON then an object is the standard way of doing it, so deserialising to one makes sense.