I want to create an endpoint for posting different types of commands. I have the option to have one route /commands which can be used for every command type or one route for each command i.e. /commands/commandA, /commands/commandB etc.

Which one of these approaches is favourable or is it a “it depends” case? What are the pros and cons of each approach?


There many approaches to this with HTTP. I’m going to ignore the security aspect of remote execution of commands and just answer the question about the endpoints.

You could POST to your endpoint with a JSON request body containing the needed data for your command:

POST /exec

  bin: 'ls', 
  opts: ['-l', '-h'] 

Alternatively, you could use GET and query strings containing all data:

GET /exec?bin=ls&opts=[-l,-h]

Or, you could go for one route per command:

GET /exec/ls?opts=[-l,-h]

Remember to URL encode all query string values.

Khám phá các thẻ bài đăng