Craigs Portfolio

9. CRUD – Update & Delete

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. 

Space background with blue and red nebula
Dynamic Web Technologies

12. Demo Feedback

522 Error on OMDB Following the 522 error I was getting on the OMDB when searching, I tested the test data on the OMDB website

Read More »
Dynamic Web Technologies

11. Conclusion

Conclusion Prior to Dynamic Web Technologies course I wasn’t interested in JSON and no idea what AJAX even was.  Whenever JSON or AJAX comes up

Read More »
Dynamic Web Technologies

10. CRUD – jQuery

Read – jQuery For jQuery consumption of the WordPress Rest API, I am using Bootstrap framework offline. I have created a quick Bootstrap layout and

Read More »