I use node.js as REST API.
There are following actions available:
- /contacts, GET, finds all contacts
- /contacts, POST, creats new contact
- /contacts/:id, GET, shows or gets specifiy contact by it’s id
- /contacts/:id, PUT, updates a specific contact
- /contacts/:id, DELETE, removes a specific contact
What would now be a logic Route for searching, quering after a user?
Should I put this to the 3. route or should I create an extra route?
I’m sure you will get a lot of different opinions on this question. Personally I would see “searching” as filtering on “all contacts” giving:
GET /contacts?filter=your_filter_statement
You probably already have filtering-parameters on GET /contacts to allow pagination that works well with the filter-statement.
EDIT:
Use this for parsing your querystring:
and in your handler (‘request’ being your nodejs http-request object):