1

According to my understandings, you should not post to get data. For example, I'm on a project and we are posting to get data.

For example, this following.

{
   "zipCOde":"85022",
   "city":"PHOENIX"
   "country":"US"
   "products":[
      {
         "sku":"abc-21",
         "qty":2
      },
      {
         "sku":"def-13",
         "qty":2
      }
   ]
}

Does it make sense to post? How could this be done without posting? There could be 1 or more products.

Khairul Islam
  • 1,207
  • 1
  • 9
  • 20
Jason
  • 103
  • 1
  • 9
  • Totally make sense when you need complex query, you can build query in json format and POST to REST in order to get data, like Elastic Search – cuongle Sep 26 '16 at 20:47
  • Possible duplicate of [Design RESTful query API with a long list of query parameters](http://stackoverflow.com/questions/14202257/design-restful-query-api-with-a-long-list-of-query-parameters) – Alexandru Marculescu Sep 27 '16 at 08:11

2 Answers2

1

Actually there is a SEARCH method in HTTP, but sadly it is for webdav. https://msdn.microsoft.com/en-us/library/aa143053(v=exchg.65).aspx So if you want to send a request body with the request, then you can try with that.

POSTing is okay if you have a complex search. Complex search is relative, by me it means, that you have different logical operators in your query.

The current one is not that complex, and you can put the non-hierarchical components into the query string of the URI. An example with additional line breaks:

GET /products/?
    zipCOde=85022&
    city=PHOENIX&
    country=US&
    filters[0]['sku']=abc-21&
    filters[0]['qty']=2&
    filters[1]['sku']=def-13&
    filters[1]['qty']=2

You can choose a different serialization format and encode it as URI component if you want.

GET /products/?filter={"zipCOde":"85022","city":"PHOENIX","country":"US","products":[{"sku":"abc-21","qty":2},{"sku":"def-13","qty":2}]}
inf3rno
  • 24,976
  • 11
  • 115
  • 197
0

One potential option is to JSON.serialize your object and send it as a query string parameter on the GET.

grayimp
  • 358
  • 2
  • 9