0

I have some logic that needs to be called by multiple applications ( mobile, web, ...). Instead of duplicating this logic, I thought of putting it in a Rest API so that I could call it from any of the applications.

The "logic" that I wish to put on my Rest API basically reads, creates and deletes multiple rows from multiple databases all at once.

But, since this "logic" executes multiple actions at the same time ( it doesn't only "GET" or "PUT" ), I feel like calling this method using the "GET" or "POST" Verbs would be weird.

So, my question is:

Is a Rest API really a good solution for this problem ?

If so, what would be the best way to handle this situation ? Should I just call it using whatever HTTP Verb I want ?

10
  • The "logic" that I wish to put on my Rest API basically reads, creates and deletes multiple rows from multiple databases all at once. -- You're looking for POST. GET and PUT don't do this. Apr 5 '21 at 1:44
  • So you mean that it would be fine to call this action with the POST verb ?
    – D.Gaulin
    Apr 5 '21 at 1:52
  • You need to be more specific with your inquiries. "Fine" is not a sufficient distinction. Apr 5 '21 at 1:55
  • 1
    "Good" is not specific enough. What does "good" mean to you? Apr 5 '21 at 1:59
  • 1
    But all that means is that your API is probably not going to be REST-conformant, and that is OK. Most web API's in use at the largest companies (Facebook, Twitter, etc.) don't actually conform to Roy Fielding's notion of REST. Apr 5 '21 at 2:13
1

If so, what would be the best way to handle this situation ? Should I just call it using whatever HTTP Verb I want ?

How would you do this with web pages?

There would probably be an HTML page with a link on it, where the link would say something like "to do everything at once, fill in this form". The link brings you to the form, which would have a submit button, and possibly some input controls to collect data. When the user clicks the submit button, the information is gathered up into an HTTP request and sent to the server.

The server then "does the thing".

Based on your description, this action doesn't sound like an essentially read-only operation; you wouldn't want anything to happen each time Google indexes your web page.

Therefore, in this design, the appropriate HTTP method to use for the form submission is POST. That's okay.

-3

Instead of randomly calling everything at once, I think you should break down your processing with steps, so that both you and the computer knows what's happening.

The reason there are GET,POST,PUT,DELETE and not a single verb available means that the software protocol wants us to use these different commands based on necessity.

A Get request doesn't tinker with database but POST,PUT & DELETE do.

May be go through the documentation for the language you are running.

I have a strong feeling that even though you could solve your problem with a single verb, as the user interaction grows, it has a high likelihood of severely damaging your database and application because of the various possibilities that you can no longer measure because you used a single verb for everything.

1
  • You can write an entire API using POST, and do it safely. I've seen it done before. Apr 5 '21 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.