KEMBAR78
REST API Design & Development | PPTX
Demystifying API
Ashok Gautam
Agenda
API Introduction
RESTFul paradigm
Design, Development & Challenges
Best practices
Tools
Resources
Q&A
API:
Introduction
What is API
Evolution
Benefits
Introduction
API stands for Application Programming Interface. API
is a set of functions and procedures allowing the
creation of applications that access the features or data
of an operating system, application, or other service.
API is a software intermediary that allows two
applications to talk to each other.
APIs have existed for a long
time. Since the first
computer programs were
written, APIs have been
providing “contracts” for
information exchange
between programs.
XML-RPC
SOAP
RESTful
GraphQL
OS APIs
Platform APIs
Application APIs
Web APIs
Evolution
Why should you have API
Efficiency
Flexibility
Integrations
Security
Metered Usages
RESTful
A RESTful API is an application
program interface (API) that
uses HTTP requests to GET,
PUT, POST and DELETE data.
RESTful
Uniform interface
Client–server
Stateless
Cacheable
Layered system
https://www.bitnative.com/2012/08/26/how-restful-is-your-api/
Design, Development & Challenges
Design
Use nouns and NOT the verbs
Use of right HTTP methods
Use Plurals
Use parameters
Use proper HTTP codes
Versioning
Use Pagination
Supported Formats
Use Proper Error Messages
https://hackernoon.com/restful-api-design-step-by-step-guide-2f2c9f9fcdbf
OAS https://swagger.io/resources/open-api/
Development
Express.js
HAPI.JS
LoopBack
Swagger
Flask
Spring Boot
Postman
JMeter
Katalon
Kong
APIGEE
Swagger
Mulesoft
FireBase
Hello World
https://medium.com/@purposenigeria/build-a-restful-api-with-node-js-and-express-js-d7e59c7a3dfb
import express from 'express';import db from './db/db';
// Set up the express app
const app = express();
// get all todos
app.get('/api/v1/hello', (req, res) => {
res.status(200).send({
success: 'true',
message: 'Hello World',
todos: db
})});
const PORT = 5000;
app.listen(PORT, () => {
console.log(`server running on port ${PORT}`)
});
'use strict';
const Hapi=require('hapi');
// Create a server with a host
and port
const server=Hapi.server({
host:'localhost',
port:8000
});
// Add the route
server.route({
method:'GET',
path:'/hello',
handler:function(request,h) {
return'hello world';
}});
// Start the server
const start = async function() {
try {
await server.start();
}
catch (err) {
console.log(err);
process.exit(1);
}
console.log('Server running
at:', server.info.uri);
};
start();
Kong
● Cloud-Native
● Dynamic Load Balancing
● Hash-based Load Balancing
● Circuit-Breaker
● Health Checks
● Service Discovery
● Serverless
● WebSockets
● OAuth2.0
● Logging
● Security
● Syslog
● SSL
● Monitoring
● Forward Proxy
● Authentications
● Rate-limiting.
● Transformations
● Caching
● CLI
● REST API
● Geo-Replicated
● Failure Detection & Recovery
● Clustering
● Scalability
● Performance
● Plugins
Challenges
Security
Authentication & Authorization
Rate Limit
Scalability
Security
HTTPS
Access Control
Restrict HTTP methods
Input validation
Validate content types
Management endpoints
Error handling
Audit logs
Security headers
CORS
Sensitive information in HTTP requests
● Parameters Exploitation
● Identity Theft
● Abusing authorization system
● Man-In-The-Middle
● DOS & DDOS
Security
Authentication & Authorization
API keys
OAuth access tokens
JSON Web Tokens
https://zapier.com/engineering/apikey
-oauth-jwt/
● Use API keys if you expect developers to build internal
applications that don’t need to access more than a single user’s
data.
● Use OAuth access tokens if you want users to easily provide
authorization to applications without needing to share private
data or dig through developer documentation.
● Use JWT in concert with OAuth if you want to limit database
lookups and you don’t require the ability to immediately revoke
access.https://blog.restcase.com/restful-
api-authentication-basics/
API : Authentication
Rate Limit
User rate limits
IP/Network rate limits
Server rate limits
Regional data limits
Resource specific rate limits
Dynamic rate limits
Leaky Bucket
Fixed Window
Sliding Log
Sliding Window
express-rate-limit
hapi-ratelimiter
flask-limiter
Rate Limit
const rateLimit = require("express-rate-limit");
app.enable("trust proxy"); // only if you're behind
a reverse proxy (Heroku, Bluemix, AWS ELB, Nginx,
etc)
const apiLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100
});
app.use("/api/", apiLimiter);
Scaling
CDN
Application level caching
Database Caching
Cloudflare/
Cloudfront/Akamai
Varnish/NGINX
Redis/Memcache
https://hackernoon.com/restful-api-design-step-by-step-guide-2f2c9f9fcdbf
https://www.apiacademy.co/lessons/2015/04/api-design-101-api-design-basics
https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design
https://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/
Resources

REST API Design & Development