Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

CS9_REST API Documentation and Versioning

The document discusses Service Oriented Computing, focusing on REST implementation, CORS, API documentation, and API versioning. It highlights the use of NodeJS, Express, and MongoDB for API implementation, as well as the importance of CORS in web requests. Additionally, it covers API documentation standards like OpenAPI/Swagger and the principles of API versioning using semantic versioning.

Uploaded by

mohit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CS9_REST API Documentation and Versioning

The document discusses Service Oriented Computing, focusing on REST implementation, CORS, API documentation, and API versioning. It highlights the use of NodeJS, Express, and MongoDB for API implementation, as well as the importance of CORS in web requests. Additionally, it covers API documentation standards like OpenAPI/Swagger and the principles of API versioning using semantic versioning.

Uploaded by

mohit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Service Oriented Computing

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,“

• This precursor to CORS was called the "Same-Origin" policy.


• When your browser loads a script from a particular domain the script can only make requests to
the domain that it originated from.

• An example of a cross-origin request:


• the front-end JavaScript code served from https://domain-a.com using XMLHttpRequest makes
a request to https://domain-b.com/data.json.
CORS Error
Preflight Request
API Documentation

• 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

• Use Semantic Versioning


• Given a version number MAJOR.MINOR.PATCH, increment the:
• MAJOR version when you make incompatible API changes
• MINOR version when you add functionality in a backwards compatible manner
• PATCH version when you make backwards compatible bug fixes
• Additional labels for pre-release and build metadata are available as extensions to the
MAJOR.MINOR.PATCH format.

Semantic versioning applied to APIs consist of just two digits: BREAKING.NONBREAKING.


References

• The Design of Web APIs by ARNAUD LAURET


• Swagger.io
• Mongoose Official documentation
• Express Official documentation
Thank You!
In our next session:

You might also like