.NET, .NET Core, ASP.NET, C#, CSharp, MVC, Programming, REST, WebAPI

HTTP Verbs in API design

HTTP Verbs are basic methods in web world. They are evolving between HTTP protocol versions but also new RFCs are published. Also they were extensions like WebDAV (with 7 methods). A full registry is maintained by IANA (here) however most of people will reply with 9 basic verbs (interesting discussion about this on stackoverflow).

Why distinction between the methods is so important? Because it precisly describe its usage. And it’s extremly important to use the right one in order to keep the same understanding about potential usage (e.g. DELETE will not create new resource).

So which methods are basic? Looking into HTTP/1.1, we have following list:

  • GET
  • POST
  • PUT
  • HEAD

HTTP/2 is not yet common on server side (browsers support it quite well but not servers). HTTP/2 extends the list with PRI method and we won’t handle it from code perspective (it’s server side handled method).

Six of them is implemented as HTTP verbs in .NET Core so they can be used on controllers (as action type indicator) to:

  • GET – retrieve the data, should not modify resource
  • POST – send the data to the resource, often causing side effects (e.g. devs are often using it to create, update and delete resources)
  • PUT – replace the resource with new payload
  • DELETE – remove the resource
  • HEAD – the same as GET but without response body (just headers)
  • PATCH – partial modify the resource

But why others are not available? Let’s consider the purpose of remaining actions to answer this question.

  • OPTIONS – to describe communication options – it’s handled on the server level, no need for additional implementation
  • CONNECT – to establish a tunnel with a server
  • TRACE – to test connectivity
  • PRI – allows HTTP/1.1 servers to parse HTTP/2 request (header not supported on client side)

So as you can note there is no point to implement such actions in your code. I hope that right now the idea of various http methods and verbs behind them is clean for you.

Leave a Reply

Your email address will not be published. Required fields are marked *