How to construct intersection in REST Hypermedia API? -


this question language independent. let's not worry frameworks or implementation, let's can implemented , let's @ rest api in abstract way. in other words: i'm building framework right , didn't see solution problem anywhere.

question

how 1 can construct rest url endpoint intersection of 2 independent rest paths return collections? short example: how intersect /users/1/comments , /companies/6/comments?

constraint

all endpoints should return single data model entity or collection of entities.

imho reasonable constraint , examples of hypermedia apis this, in draft-kelly-json-hal-07.

if think invalid constraint or know better way please let me know.

example

so let's have application has 3 data types: products, categories , companies. each company can add products profile page. while adding product must attach category product. example can access kind of data this:

  • get /categories return collection of categories
  • get /categories/9 return category of id 9
  • get /categories/9/products return products inside category of id 9
  • get /companies/7/products return products added profile page of company of id 7

i've omitted _links hypermedia part on purpose because straightforward, example / gives _links /categories , /companies etc. need remember using hypermedia traversing relations graph.

how write url return: products company(7) , of category(9)? in otherwords how intersect /categories/9/products , /companies/7/products?

assuming endpoints should represent data model resource or collection of them believe fundamental problem of rest hypermedia api, because in traversing hypermedia api traversing relational graph going down 1 path impossible describe such intersection because cross-section of 2 independent graph paths.

in other words think cannot represent 2 independent paths 1 path. traverse 1 path a->b->c, if have x->y , z->y , want ys come x , z have problem.

so far proposition use query strings: /categories/9/products?intersect=/companies/9 can better?

why want this?

because i'm building framework auto-generate rest hypermedia api based on sql database relations. think of trans compiler of urls select ... join ... where queries, client of api sees hypermedia , client have nice way of doing intersections, in example.

i don't think should @ rest database representation, case looks more of kind of specific functionality me. think i'd go this:

/intersection/comments?company=9&product=5

i've been digging after wrote , i've found (http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api):

sometimes have no way map action sensible restful structure. example, multi-resource search doesn't make sense applied specific resource's endpoint. in case, /search make sense though isn't resource. ok - what's right perspective of api consumer , make sure it's documented avoid confusion.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -