Implementing business rules into a REST api

123 views
Skip to first unread message

Daniel Rhéaume

unread,
Oct 25, 2017, 9:27:45 PM10/25/17
to API Craft
Hi all,

I am looking for the best practices related to the implementation of business logic into a REST api. The use case we have to support is the following. We have a GET method on a resource that must include a calculated value (the calculation is based on a business rule) in the data it returns to the consumer of the API. This is a very simple problem but we want to make sure we use a clean and valid REST pattern to do so. Is it okay that this rule is implemented directly in our resource? Should we isolate the business rule in a separate resource? Any other pattern we should know about?.

Your advices will be welcomed.

Regards,

Dan

Lukas Rosenstock

unread,
Oct 29, 2017, 2:25:42 PM10/29/17
to api-...@googlegroups.com
Hello Daniel,

I’m not sure if I completely understand your requirement but generally I would say that a GET on a resource can include any calculated value; a REST resource should be a noun that can be named, not an action, and it should be idempotent, but how the value is derived is not important. To be RESTful you should NOT have any action/verb in the URL, i.e. GET /calculateValue would not be recommended. If the business rules are different for different users of your API it could be a good idea to store these rules under names and have this name in the URL so you can extend to support multiple rules later.

This is all I have for now, if you could provide more information about your API and use case I could probably offer some more specific advice.

Lukas Rosenstock



--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+...@googlegroups.com.
Visit this group at https://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages