2

We've come across the following case when working on REST API.

Users have the ability to expand the product deployment by installing custom JSON configurations. These configurations tend to be lengthy and are generated automatically.

We're working on implementing an API call for installing and updating such configurations. The use-case we try to cover is when user updates an existing configuration, and wants to set the overwriting strategy. Typically we would include such option in the POST/PUT request body. But, since it might be difficult/error-prone for end users to manipulate a lengthy JSON, we want to avoid any changes to the generated JSON configuration.

Are there any best practices for such cases? We thought of passing an "overwrite" parameter in URL, which isn't quite RESTful, but is simple for end users.

4
  • 4
    It's not entirely clear what the overwrite parameter does, but it sounds like it alters the meaning of the HTTP POST/PUT, which wouldn't be advisable. I don't exactly understand the requirement, but you may want to look into PATCH method as an alternative for clients that only want to set a subset of values.
    – mahemoff
    Mar 7, 2017 at 9:34
  • whenever you are making something worse because 'its RESTful'. stop
    – Ewan
    Mar 7, 2017 at 11:36
  • 1
    Why not just use POST /configurations to add a new configuration (with possibly an error if the new configuration couldn't be added) and POST /configurations/<id> to update an existing configuration? Mar 7, 2017 at 13:27
  • Are there any best practices for such cases? We thought of passing an "overwrite" parameter in URL, which isn't quite RESTful - if your api is restful then your client won't notice. The url is not hardcoded in clients, that is the point of restfulness. The url is provided by the server and discovered by the client by using a "rel" or similar attribute for the link. Mar 8, 2017 at 21:52

1 Answer 1

1

It sounds like you might actually have two different resources — generated configurations, and user configurations — each with their own RESTful interfaces.

In this design, users would only be allowed to apply user configurations, which would be created by cloning generated configurations. Those user configurations could then be modified directly without the possibility of overwriting the original generated configurations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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