0

I am learning how to build a website with node.js +express. When I click on a button (in the browser), it prints "hello" in the node.js console. It worked (this is not the problem). To do that, I created a app.get route.
But I wonder which http request methods (https://www.rfc-editor.org/rfc/rfc7231#section-4), I should use to conform to the REST architectural style.

  • GET must be used to read
  • POST must be used to create
  • PUT must be used to update and to create
  • DELETE must be used to delete
  • ...

I do not read, create, update, delete, ... anything. I just run a command on the server (Of course, print hello is not the final goal. I plan to run more complex commands).

Thanks for answer.

1
  • 1
    It will depend on what "command" you want to run. REST is all about "resources". See medium.com/qudini-engineering/… for a quick overview. Commented Jan 15, 2021 at 11:50

1 Answer 1

1

a) there is no "REST standard" - it's an architectural style; HTTP can be used to implement "RESTful" services

b) PUT is for creation as well

c) How your server does things (such as by "executing" something) doesn't really matter. Think in terms of URIs, the resources they identify, and what you can do with them.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answer. I edit my question following your a and b points. If I understand the c point : I must use GET if I change nothing in the resources. Right ?
If the server does not change state, GET should be always correct.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.