1

I have product_id and onec_id columns to get items from DB. Which API routes should I use to get items by product_id or by onec_id?

Is it right for REST routes?

GET /products/{product_id}
GET /products/get_by_onec_id/{onec_id}
3
  • 1
    What Resources are identified by these IDs? What do you mean by 'multiple item id'? Commented Nov 1, 2012 at 10:13
  • I need to get products in two ways: - by product_id - by onec_id Commented Nov 1, 2012 at 10:18
  • Are you writing an api or consuming one? Commented Nov 1, 2012 at 10:32

2 Answers 2

1

The most REST solution is to fire one HTTP request for each id. For example

GET /product/736

REST is intended to represent the state of a resource. It can return a set of items, but only if these items relate to each other in some way. For example

GET /onec/492/products

Will return the set of products associated with the specified onec.

If you want to return the set of products identified by a set of IDs in a single request, you may have your shortcut syntax like

GET /products/12,768,56,086

But it's not really common because it's quite a departure from the REST objectives

Sign up to request clarification or add additional context in comments.

1 Comment

decided to write routes in such way: GET /product/id/:id GET /product/onec/:id
1

To get a single Product or Onec(?), GET

/products/{id}
/onecs/{id}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.