Utilizing PATCH on an image

Options
NWold
NWold Member

How would I go about editing an image through PATCH? For example a user's profile picture.

Tagged:

Answers

  • arturosanz
    arturosanz Member ✭✭
    edited October 2023
    Options

    HTTP defines a set of methods (GET, POST, PUT, PATCH, DELETE, …) to indicate the desired action to be performed for a given resource. Those verbs do not perform any specific action on the backend. You could edit an image using any of them, but of course, you should follow the rules and use them properly. For instance, GET should only be used to retrieve data from the server, and you will have limitations by using it because sending body/payload in a GET request may cause some existing implementations to reject the request.

    You should consider using PUT or PATCH to edit an image. PUT should be used when you substitute the entire resource for a new one, and this request will be idempotent. No matter how many times yo make the same request, the effects will be the same. PATCH should be used when you partially modify a resource, and this request is not idempotent. For instance, incrementing a counter value of a record field repeated times will change the record data every time, for example, liking instagram posts.

    When you edit an image you will likely substitute the old image for a new one, and repeating the same request won't change the result, so PUT is the correct verb to use in your case.

    Here you have a help video on handling images with Xano: