Now that we, hopefully, have a decent basis of knowledge about REST and REST API’s we can finally begin discussing the specifics on implementing a REST API. I am afraid that, once again, I will run out of space before being able to cover all of the aspects of REST API creation so I encourage any readers to check the source I am referencing for this post. My source is a pretty well laid out tutorial that has a step by step guide on each part of this process. This is what I have been doing most recently in my coursework so it is nice to finally reach some directly relevant information. Granted much of the surrounding code was already done for us, so some of this will be brand new to me, but we have been designing some endpoints. All of that aside, let’s just jump right into it.
Well actually one more quick note before we begin, this tutorial is using Docker, which you can read about in one of my earlier posts. Additionally there are some parts of this web application that are already completed, so you can download this to follow along with the tutorial if you want. This example is just a database for a generic company with employee information, created with javascript. I am not going to go too deep into detail about creating all of these files to make the web application, as that is an entirely different topic. The first thing to note when implementing a REST API is an acronym, CRUD. Essentially this means that your API should create, retrieve, update, and delete. The equivalent methods to these are post for create, get for retrieve, put or patch for update, and delete for delete believe it or not. One other important part of implementing a REST API is handling response codes. The codes that you may want to account for can vary for each function, for example a function that edits data will use response code 201. To do this you can add a section for request handling at the end of your openapi.yml file. Here you can specify specific messages to be returned by each HTTP response code that gives more specific feedback based on your web application. And I am afraid that is all I have space to discuss, once again coming up a bit short.
Well, as I said in my first post, I vastly underestimated the sheer amount of information there was about REST API’s. I really tried my best to give some information about them, but there is still so much more that simply could not fit into these three blog posts. I would definitely try to follow along with a tutorial implementing a REST API either with docker or flask, as I saw both when researching this post. Regardless I found this information helpful and I hope any readers did too.
Source
From the blog CS@Worcester – My Bizarre Coding Adventures by Michael Mendes and used with permission of the author. All other rights reserved by the author.