DEV Community

Discussion on: What **is** an API?🤷🏼‍♀️ Part II

mastacheata profile image
Mastacheata • Edited

There's actually one more very important HTTP-verb used in APIs (including the GitHub one) and that's called PATCH.

PATCH is very similar to PUT in that they're both used to change stuff that's already there. The difference is how they achieve that:

  • PUT takes whatever item you want to change and replaces it with whatever you send in the PUT-Request.
  • PATCH on the other hand takes the item you want to change and only updates those fields you send in the PATCH-Request. It's therefore sometimes called a partial update as well.

Let's take a look at the GitHub issue example from the OP:

The fields you can modify in an issue are the title and text (and a bunch of other things I'll not mention here):

  • In order to change the title of your issue using PUT, you have to send both the changed title as well as the original text of the issue (and all the other fields I didn't mention).
  • With a PATCH request on the other hand you can just send the title and not send the text at all.
javascriptcoff1 profile image
JavaScript➕Coffee🚀 Author

Great points, thanks for your additions! I have a couple of questions about this, I'll DM you on Twitter and maybe we can work some of this into the post if you are happy with that :)