RESTful APIs
Team I Tech Talk
Wid Alsadoon - Fariha Marzan - Janet Mbugua - Natalie Yuziuk
Background
History
Previously (1999): SOAP (Simple Object Access Protocol)
Then (2000): Roy Fielding & colleagues set to create standard
Definition
API (Application Programming Interface):
REST API (Representational State Transfer API):
Key Features of RESTful APIs
RESTful API is:
Purpose
Benefits of RESTful APIs
Motivation
Client and Server Communication is vital to applications!
Function Usages
Example: GET api.marker.io/?color=Black
How we’re using Rest API
Express.js used as backend framework for building RESTful APIs with Node.js
Controllers required for each survey type
How we’re using Rest API
GET, POST, DELETE from REST seen above…
PATCH is like PUT, but only updates fields instead of entities (introduced to reduce bandwidth usage)
How we’re using Rest API
Example of person survey GET; used for retrieving person survey records from Mongo database or throwing error if the action fails
How we’re using Rest API
Demo
Follow Along!
Step 1: Initialize Server
Importing path, express
& body-parser
Initializes the Express server and sets it to a variable called app
Initializes the body-parser plugin
Setting our server to listen on port 5000 for requests
Step 2: GET data from REST server
Creates function for API to use on request. Calling GET request on ‘/’
Using .sendFile, any file can be sent as a response. In this particular case, the user will access the index.html page when they try to navigate to ‘/’.
Step 3: Connect to server
If successful, should return a corresponding statement such as:
Step 4 : POST data to REST server
Then returns the output to the REST server via POST
Within index.html
Creating a power function takes in the requested input and raises it to the power
Step 4 : POST data to REST server
Add function takes in the requested input and raises it to the power
Multiply function takes in the requested input and raises it to the power
Demo Clip
Bad Service Requests
Let’s Try It Out
Choose one of these fun databases to pick from so you can try it!:
Q&A
(Questions?)
Possible questions:
Alternatives to REST: https://blog.bitsrc.io/not-all-microservices-need-to-be-rest-3-alternatives-to-the-classic-41cedbf1a907