Erik Moldtmann
Erik Moldtmann

Reputation: 164

Call remote procedure in a RESTful way

I want to make a webservice which provides endpoints through which a user can generate and manipulate configuration files saved in a database. The endpoint

https://api.example.com/generate-new

should execute a procedure which generates a standard configuration file for the user. A RESTful webservice should return the complete config file as an answer (state transfer). Since the config files also contain sensitive information like api keys, this is not possible here.

I would like to only return a success message. A HTTP-200 would be enough. But is this approach still RESTful?

Upvotes: 0

Views: 247

Answers (1)

user8098055
user8098055

Reputation:

Ask yourself: What is the Resource (the 'R' in REST) here? It sounds like the Resource is something like a User Configuration Generation Task. The URL should reflect this:

https://api.example.com/user-configuration-generation-tasks

Let's say a HTTP POST request to this collection resource creates a new task, maybe using information passed in the request body. The server executes this task and generates the new user configuration.

Now you have three options for what to return:

  • 201 CREATED: This would require to include the Location of the user configuration in the response. Since you don't want to make the configuration accessible, this is no option.
  • 200 OK: This would indicate general success of the operation. But since you don't plan to return any response, I don't suggest this. Instead us
  • 204 NO CONTENT: The server has successfully fulfilled the request and there is no additional content to send in the response payload body.

All this is perfectly RESTful.

Upvotes: 1

Related Questions