CS9_REST API Documentation and Versioning
CS9_REST API Documentation and Versioning
Akshaya Ganesan
Assistant Professor[Off-Campus]
BITS-Pilani
Precap
• REST alternatives
• gRPC
• HTTP/1.1 vs HTTP/2
Agenda
• REST implementation
• Methods and libraries
• CORS
• API Documentation
• API Versioning
API Implementation
Using NodeJS, Express and MongoDB
• /Products
• /orders
Create app.js
• Create server.js
const express = require('express');
•
const app = express();
• const http= require('http');
• const port=process.ENV.PORT || 3000 environment variable
app.use((req, res, next) => {
•
res.status(200).json({
• const server = http.createServer(); //listener pending
message: "Im up!'
• server.listen(port); });
• }); //sets middleware
• module.exports=app;
CORS
CORS is an acronym for Cross-Origin Resource Sharing
• [CORS] is a mechanism that allows restricted resources on a web page to be requested from
another domain outside the domain from which the first resource was served,“
• API documentation is a technical content deliverable containing instructions on using and integrating
with an API effectively.
• API description formats like the OpenAPI/Swagger Specification have automated the documentation
process, making it easier for teams to generate and maintain them.
• OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs.
• An OpenAPI file allows you to describe your entire API, including:
• Available endpoints (/users) and operations on each endpoint (GET /users, POST /users)
• Operation parameters Input and output for each operation
• Authentication methods
• Contact information, license, terms of use and other information.
• API specifications can be written in YAML or JSON.
What Is Swagger?
http://swagger.io/docs/specification/basic-structure/
• Swagger is a set of open-source tools built around the OpenAPI Specification that can help you
design, build, document and consume REST APIs.
API Documentation
An OAS document describing the search for products goal of the Shopping API
API Versioning
API versioning
API versioning is the practice of transparently managing changes to your API.
• MAKING MINOR, BACKWARD-COMPATIBLE CHANGES
• MAKING MAJOR, BREAKING CHANGES
• URI Versioning
• Query Parameter Versioning
• Custom Headers