Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a REST client frontend for a REST API backend?

I've built a REST API backend using Django and am now at the stage of designing a client facing frontend. Though, I can't seem to understand how this client frontend should be structured and which languages it should use.

PHP is server-side, and is usually used as the language for building backends. When coupled with a framework such as Codeigniter, it can also be used to play around with sessions, route URLs, and decide which templates to use. Though, I don't believe it can be used to call my REST API to fetch resources (might be wrong here, correct me please if I am).

Javascript is client facing but is used only once the webpage has been fetched from the server. AngularJS is great, but from what I've read, it seems it only helps add very dynamic functionality into already rendered static pages.

I am really open to any ideas, suggestions, and advice based on your experiences creating client frontends. So, back to my original question, how does one structure a REST client frontend, which language is best for this goal, and if which frameworks should one consider to use?

Update 1

Someone asked whether this client frontend will be run in a browser -- the answer is yes, it will. I am trying to build a Twitter-like web client frontend that interacts with a Twitter-like REST API backend. Basically, everything you see there when you go on Twitter's website.

like image 795
heapoverflow Avatar asked Feb 22 '15 02:02

heapoverflow


People also ask

What are REST APIs and why are they important?

In Web Development, REST APIs play an important role in ensuring smooth communication between the client and the server. You can think of the client as the front end and the server as the back end.

What is the difference between a REST API and a front-end?

However, an API may be called a REST API even if the front-end does not obey all REST principles. In that case, you are free to design your REST API with other considerations in mind, e.g. performance, reusability, flexibility. I would recommend the latter. You may call multiple API resources for rendering a single page.

What is the root endpoint of a RESTful API?

The root endpoint of a RESTful API is the initial endpoint of the API. It is the entry point of the API and the only endpoint that a RESTful client should know.

What is a restful client list?

"REST is a set of principles, it is not a formal standard." The final resource that will be sent to the RESTful client contains the list of customized clients and is tagged as client - list via the resourceType property.


3 Answers

Since it is a browser frontend I would go with HTML/JavaScript only. No need to use PHP or any server side language IMHO. This has the advantage of being extremely portable.

I would also use a JS framework for that purpose ( the trend nowadays seems to be angular).

like image 184
Tivie Avatar answered Oct 11 '22 23:10

Tivie


REST really, really isn't new. It's been a part of HTTP at least as far back as HTTP 1.1

Have a look at this question: Backbone.js frontend with RESTful Rails backend? the top answer lists 20 possible frameworks for building a front end.

like image 42
Andy Preston Avatar answered Oct 11 '22 21:10

Andy Preston


Thanks for your help, everyone. Found exactly what I was looking for here: http://docs.python-requests.org/en/latest/

A nice little library for Python that allows me to basically make calls to a REST backend from within a Django application, which serves as my frontend.

AngularJS will also be used for to make the static pages that Django returns more dynamic. Why? Because AngularJS by itself can be the complete solution only if your whole site consists of one page. If you have multiple pages where each one has it's own set of dynamic elements, you need a combination of Django and AngularJS.

Apparently REST is still quite new and it seems there aren't many people that have stumbled upon this very fundamental question like I have.

Once again, thanks!

like image 40
heapoverflow Avatar answered Oct 11 '22 22:10

heapoverflow