Vindberg
Vindberg

Reputation: 1552

RESTful naming: a POST call that is a GET?

In our API it should be possible to get all the metadata on some objects (can be over 1000 ids). But how should the endpoint look like?

It is okay to make a POST api/objects/getmetadata with the following body?

Body:

{
"Objects":[
{ 
"Id":23232,
"Id":3243,
"Id":3243,
...}
]}

Upvotes: 0

Views: 274

Answers (1)

lefloh
lefloh

Reputation: 10961

If you can provide a few parameters which identify the IDs just use GET with query-parameters like this:

GET /customers?minId=1000&maxId=2000

or

GET /customers?minSalary=500

You could also use matrix-parameters if you want hierarchical filtering of only one segment of the URL.

GET /api/objects;minId=1000/metadata

If this is not possible and you need to pass the full list of maybe 1000 IDs a POST is absolutely valid but you should treat it as a request which creates a new resource on the server:

POST /api/metadata-search

{ "objects" : ... }

The server should return the newly created resource:

HTTP/1.1 201 Created
Location: /api/metadata-search/4711

This way the result has the advantages of a GET and can be cached, bookmarked and so on.

Upvotes: 2

Related Questions