-
-
Notifications
You must be signed in to change notification settings - Fork 158
Question: Multiple business operations on the same resource? #937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @hainguyenthanh, I'm afraid there is no single obvious answer to this question. JADNC is quite flexible in this regard. You can add non-json:api controllers with custom routes (for example: POST /actions/publish-article) to the same project (derive from In case the "operations" you're referring to solely represent data changes, they can simply be modelled as attributes on an existing resource. In your example, that would mean adding: [Attr]
public bool IsApproved { get; set; }
[Attr]
public bool IsPublished { get; set; } to the Article class. On the other hand, if 'approval' refers to initiating an async workflow (like sending an email, waiting for an authorized user to receive that, login and click Approve in some UI, then notify the requester of the state change, etc.) this may be best handled by another software component higher in the architecture. In microservices terminology, a saga would drive such a workflow and send multiple simple state changes to a json:api endpoint over time. The json:api endpoint could enqueue a notification message on the service bus after saving the changed resource, allowing multiple interested systems to subscribe to that. From my point of view, the REST style (even at lower levels without hypermedia) is conceptually similar to the world wide web: a collection of documents (http resources) with relationships (http urls) that link them. Http requests then are concerned with managing the content of documents, instead of executing functions. If your operations represent synchronous commands/rpc/functions, but you want to expose them via the REST style, then the challenge becomes to model them as changes to documents and the relationships between them. See https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/ for more details on these conflicting styles. Some attempts for this kind of modelling can be found at https://softwareengineering.stackexchange.com/questions/338666/how-does-a-rest-api-fit-for-a-command-action-based-domain and https://stackoverflow.com/questions/22322468/is-bad-practice-to-mix-rest-and-rpc-together. Hope this helps. |
Hi @bart-degreed, thanks for your informative reply. I'm closing the question now. |
Add a x-command-type header and use JADNC services to issue the required command if there is one.
REST really lacks in this area IMO and the guidance is pretty conflicting. At the end of the day do what works for you within the bounds of the various specs - but that’s a higher level spec thing not anything JADNC has done. JADNC does offer a lot of extension points for hooking in and doing this stuff tho so that’s good. Would be good if there was a simple facility for this that was formalised but not sure that’s something they’d be interested in?
Wayne
…On 17 Feb 2021, 03:05 +0000, hainguyenthanh ***@***.***>, wrote:
Hi @bart-degreed, thanks for your informative reply. I'm closing the question now.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Hi there, in one of the projects using JADNC, I need to support various business operations on a single resource. For example, given an
Article
resource, besides the basic operations such as Create, Edit, Get that nicely map to the POST, PATCH, GET HTTP methods, I also need to do various operations on this resource such as Approve, Publish, Unpublish, etc.Is there any way to do this using JADNC or JSON API in general?
Thank you,
The text was updated successfully, but these errors were encountered: