What is RESTful API?

REST APIs handle the server side of the web application. That means that the backend is built once and can provide content or data for frontend, mobile, or other server-side apps. A great example is the google calendar API.

REST stands for Representational State Transfer and is a way how a web server should respond to requests. This allows to not only read data, but also do different things like updating, deleting or creating data.

I’m going to build an API that allows to create questions and create, edit, vote and delete answers.

For programming the API it is key to structure the routes properly.

Therefore we need to be able to program routes to:

look at existing questions and create our own
read, create, edit, delete answers
vote on answers

What I will use for this introduction
Development Environment
In this example here I will use

Plain JavaScript

Express (JS framework)
MongoDB (Database)
Yarn (package management)
Visual Studio Code as editor
Postman (testing APIs)

Following packages are used

body-parser (for parsing incoming requests)
express (to make the application run)
nodemon (restarting server when changes occur)
mongoose (object data modeling to simplify interactions with MongoDB)
morgan (HTTP request logger middleware )
eslint with Airbnb extension (for writing higher quality code)

The tutorial will be structured in:

building the API routes with express
modeling data for the API
communicating with Mongo through Mongoose
finalizing and testing the API

Leave a Reply

Your email address will not be published. Required fields are marked *