This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Search Implementation in REST Service  RSS feed

 
Ranch Hand
Posts: 370
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are developing the RESTful services for search operations. As per REST Specs, since we are fetching the data from the server, it must be GET HTTP Method. But, we have to search on a huge number of parameters and this list can extend in future too. And, there is a limit to the query URL length, so, all search parameters can't be able to fit in the query URL. So, how can we implement this search?
 
Saloon Keeper
Posts: 5052
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By using POST. Why would REST principles forbid using POST for a search?
 
Bartender
Posts: 9498
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really forbid, but POST is used when you want to make a non-idempotent change on the server. I agree with Vaibhav that a GET is more appropriate.

However, when technical limitations bind your hands, you don't really have a choice. I would use PUT rather than POST though, as PUT indicates you can replay the request and it will return the same results, as long as the server state hasn't changed between the two requests.
 
Marshal
Posts: 67165
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A past implementation:

A POST is used to create a re-usable search query resource. A GET is used to fetch the results of running a parameterized search using the query resource.

Pure REST.
 
Saloon Keeper
Posts: 2156
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vaibhav Gargs wrote:We are developing the RESTful services for search operations. As per REST Specs, since we are fetching the data from the server, it must be GET HTTP Method. But, we have to search on a huge number of parameters and this list can extend in future too.


Your RESTful API should be focused on the exchange of specific resources.  When GETing a resource from a server, the client should already know what type of resource it wants the server will provide, and the majority of the parameters which describe the resource should be in the URI's resource path, not query parameters.  A quick example:

RESTful:
    GET /api/auto/dodge/caliber/2015/parts/engine/cooling/hose/intake&engine=2.2L

Not RESTful:
    GET /api/search?category=auto&type=parts&system=engine&subsystem=cooling&item=hose&use=intake&make=dodge&model=caliber&year=2015&engine=2.2L

 
Stephan van Hulst
Bartender
Posts: 9498
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a source for that Ron? What makes it not RESTful?
 
Ron McLeod
Saloon Keeper
Posts: 2156
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Do you have a source for that Ron? What makes it not RESTful?


In my example, the path /api/search does not describe a resource, it describes a operation.
 
Stephan van Hulst
Bartender
Posts: 9498
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fair point.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i am working on something that will completely eliminate the need for coding for setting up a web server for answering REST web services or needing to sign up to a database provider like Oracle Rest Data services. The solution will allow business users to create dataflows and workflows for defining business logics for individual responses for REST requests.


I am just interested in knowing how much this project will gain traction among business users and developers.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!