Latest Project - RESTful APIs

Jul 17 2018

Picture here

It's been a while since I've posted, but that's because it's been quite a busy month. I've worked on a few different projects and courses simultaneously and have finally completed one of the major ones.
You can check it out via the navigation bar link "Project V- Handy Dev Hints".


I wanted to learn more about APIs and REST methodologies so I I put together a simple API using Django's REST Framework. API stands for Application Program Interface and is basically a way for one program to communicate with another, for example a client accessing information from a database can be done through an API.


One of the major benefits of API as I understand it is that the data gets converted to JSON which can be read on any machine; a Windows, Linux PC or Android phones. Thus you don't need to worry about making sure that each device will be able to access the data without problems.


I managed to create a basic functioning API without much trouble, thanks in part to DRF (Django REST Framework) and the in-built classes that it has e.g Serializer class. However, I did face numerous challenges when I wished to expand my project. Primarily, I wanted to create a HTML page of my data that was accessible through the API. I first had issues rendering objects to HTML using various commands such as generics APIView. I overcame this problem myself by changing the view to a Viewset (still utilising renderer_classes = [TemplateHTMLRenderer]) and making sure that my url reflected the view class (url(r'^html/', HTMLAPIView.as_view({'get': 'list'}), name='html' )).


Now, even though my HTML page looked ok, i wanted it to function well also. The next challenge I had was simply connecting the individual API objects to their HTML representations. Stack Overflow and Daniel Roseman helped with this . The important missing piece was including the namespace as well as the name in the urls and making sure the pk=query.pk matched.


In the end I am pleased with the result, however the project is not compete because I am struggling with some base HTML template issues with the Browsable API. Regardless, the project was a great learning curve. I have another JavaScript project underway currently that I hope will result in giving the blog a bit more flare.