Skip to content

Instantly share code, notes, and snippets.

View justlaputa's full-sized avatar
:octocat:
coding 🐾🐾

Han Xiao justlaputa

:octocat:
coding 🐾🐾
  • PayPay
  • Tokyo, Japan
View GitHub Profile

API Design Patterns And Use Cases

This document lists various useful patterns for API design. We encourage API developers to consider the following patterns as a guide while designing APIs for services.

Document Semantics, Formatting, and Naming

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

The words "REST" and "RESTful" MUST be written as presented here, representing the acronym as all upper-case letters. This is also true of "JSON," "XML," and other acronyms.

API Design Guidelines

Introduction

The PayPal platform is a collection of reusable services that encapsulate well-defined business capabilities. Developers are encouraged to access these capabilities through Application Programming Interfaces (APIs) that enable consistent design patterns and principles. This facilitates a great developer experience and the ability to quickly compose complex business processes by combining multiple, complementary capabilities as building blocks.

PayPal APIs follow the [RESTful][0] architectural style as much as possible. To support our objectives, we have developed a set of rules, standards, and conventions that apply to the design of RESTful APIs. These have been used to help design and maintain hundreds of APIs and have evolved over several years to meet the needs of a wide variety of use cases.

We are sharing these guidelines to help propagate good API design practices in general. We have pulled extensively from the broader community and believe that it is importan

@justlaputa
justlaputa / callee-health.js
Created September 21, 2019 09:52
kubernetes-graceful-shutdown-poc
const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
const APP_NAME = 'callee'
const WAIT_BEFORE_SERVER_CLOSE = parseInt(process.env.WAIT_BEFORE_SERVER_CLOSE) || 5
app.get('/api/ok', (req, res) => {
res.send('ok')
@justlaputa
justlaputa / callee-v2.js
Created September 21, 2019 08:48
kubernetes-graceful-shutdown-poc
const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
const APP_NAME = 'callee'
const WAIT_BEFORE_SERVER_CLOSE = parseInt(process.env.WAIT_BEFORE_SERVER_CLOSE) || 10
app.get('/api/ok', (req, res) => {
res.send('ok')
@justlaputa
justlaputa / caller.js
Created September 17, 2019 23:24
kubernetes-graceful-shutdown-caller
const axios = require('axios')
const APP_NAME = 'caller'
const CALLEE_URL = process.env.CALLEE_URL || 'http://localhost:3000'
//number of request per second caller will call the callee's api
const REQUEST_RATE = parseInt(process.env.REQUEST_RATE) || 10
const apiClient = axios.create({
@justlaputa
justlaputa / callee-v1.js
Last active September 17, 2019 23:16
kubernetes-graceful-shutdown-poc
const express = require('express')
const app = express()
const PORT = parseInt(process.env.PORT) || 3000
const APP_NAME = 'callee'
app.get('/api', (req, res) => {
res.send('ok')
})
@justlaputa
justlaputa / bookmarklet.js
Created September 28, 2018 06:24
highlight webpage links
javascript:(function(){var%20host=window.location.host;var%20goog=%22http://www.google.com/s2/favicons%3Fdomain=%22;var%20links=document.getElementsByTagName(%22a%22);for(i=0;i%3Clinks.length;i++){var%20link=links[i];if(link.href.match(%22^https%3F://%22)%26%26%20!link.href.match(host)){domain=link.href.split(%22/%22);link.style.background=%22yellow url(%22+goog+domain[2]+%22)%20center%20left%20no-repeat%22;link.style.fontWeight=%22bold%22;link.style.fontSize=%22105%25%22;link.style.padding=%225px%205px%205px%2020px%22;link.style.textDecoration=%22underline%22;}}})();
@justlaputa
justlaputa / unstar-all-repos.md
Last active September 29, 2024 10:33
How to unstar all your github starred repos
var app = express()
// handle GET /foo
app.get('/foo', function (req, res, next) {
res.end('foo')
})
// define a route and a group of handlers
app.route('/book')
.get(function (req, res) {
var app = express()
var bodyParser = require('body-parser')
// third party middleware
// parse application/json
app.use(bodyParser.json())
// user defined middleware
app.use(function (req, res, next) {
console.log('Time:', Date.now())