POSTMAN PUT/PATCH - Update
As I am using the WP Rest API, a PUT request does the same thing as a POST request. So for updating data using this API, it is possible to use either HTTP method. There is also a PATCH request option which is similar to PUT. The difference between these are the PUT sends all the data, even unchanged data to be overwrite the original data. PATCH sends only the data that has been changed to be updated.
For good practise I will use a PATCH request. I found information supporting both PUT and PATCH but the most efficient way to code is with a PATCH request as it does override the same data on an update.
As shown on the POST request, I successfully created a POST request and added a new blog post but without a featured image. I then added a media image with the id of 189. The argument for a featured image is “featured_media” which I set to 189 and make a PATCH request to change the image only which is successful as shown below.
POSTMAN DELETE - Delete
A delete request will look something like this. This is a hard delete to purely show the code. This is not something I would use to remove a blog post or a page as once its gone it can no longer be recovered. Normally when a page like this is deleted then a re-direct would be setup to cover any issues within SEO.
The post I created called Post Title 1 using Postman and edited an image into it I will now delete via Postman and the second screenshot will show it in the Trash.
This is the CRUD functionality of the WP Rest API working correctly using Postman. The only thing I forgot to include during the Create method was the category.
All these examples are currently within Postman. I remembered after spending alot of time doing and making these that the point of the project is jQuery. I didnt understand what I was doing or JSON for that matter, so this has helped me tremendously in working out what/how JSON works. I lost sight of that fact but without doing this, I wouldnt have been able to complete my Weather and OMDB shown in the previous blogs.