Lets say I have a REST API where developers can publish offerings of properties (adress, price, living space) using
POST /offerings
Users can browse these offerings using
GET /offerings?page=0
Now I have a problem. Commercially used properties are handled on a different service (although they do end up on a common database)· The easiest way would be a separate endpoint and then redirect it using nginx.
POST /commericalOfferings
But is this still restful design? I was looking through a bunch of definitions for restful design but I can’t come up with a clear answer.
Especially since theres no GET
for commercialOfferings
So does anyone know if this is still a valid architecture?
2
Answers
It’s fine.
There is nothing in REST that requires that information have one-and-exactly-one resource.
As always, your basic heuristic for "it is RESTful" is to ask yourself: does it behave like a web site? If it does, then you are good.
It is okay, though I would do something different:
REST doesn’t cover such design decisions, it works on a higher abstraction level. It just says that you must follow standards like HTTP, URI, etc. to build a uniform interface, something similar to OOP interfaces just on an inter-application communication level not on an inter-object communication level. Having nice URI-s like the upper is not a REST constraint either, nice URIs are just an unofficial recommendation, not a standard to follow. https://en.wikipedia.org/wiki/Clean_URL In REST there is a constraint called HATEOAS, which means you send hyperlinks in your responses and the client follows these hyperlinks – like you follow them by browsing a web page – instead of having hardcoded URI templates or building the URIs themselves, this is why from client perspective the URI structure does not matter at all. HATEOAS is part of the uniform interface constraint. And every REST constraint is mandatory except code-on-demand. https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm From service perspective the URI structure matters, it is easier to configure the router if you follow the nice URI recommendation.