Skip to content

idea2app/GitHub-RESTful-middleware

Repository files navigation

GitHub-RESTful-middleware

Express & Koa compatible middleware for GitHub RESTful API

NPM Dependency CI & CD

NPM

Version

SemVer branch status language framework API schema
>=0.6 main ✅developing TypeScript Express & Koa Swagger
<0.6 master ❌deprecated ECMAScript Express APIDoc

Feature

  1. OAuth 2.0 (Production Environment can be used for debugging of localhost)

  2. API Proxy (HTTP-only Cookie Session instead of Access Token is easy to use for Web front-end)

  3. Wrapper APIs to get the Technique(Language) list of a User or Organization

  4. Diff to HTML (Get /repos/:owner/:repo/pull/:pull_num.diff with Accept: text/html, the Diff Code will be converted to HTML by diff2html)

  5. One Hook URL to receive all kinds of Event

  6. 3 APIs of Server-sent events about Organization & Repository

Usage

with Koa

The sample codes shown below will serve all the APIs of GitHub RESTful middleware with Koa, Swagger UI + JSON spec & Mock APIs.

Install command

npm i github-restful-middleware koa koa-logger koa2-swagger-ui koagger routing-controllers

Core logic (index.ts)

import Koa from 'koa';
import KoaLogger from 'koa-logger';
import type {} from 'koa2-swagger-ui';
import { createAPI } from 'koagger';
import { useKoaServer } from 'routing-controllers';
import { controllers } from 'github-restful-middleware';

const { NODE_ENV, PORT = 8080 } = process.env;
const isProduct = NODE_ENV === 'production';

export const { swagger, mocker, router } = createAPI({
    mock: !isProduct,
    controllers // other controllers of your own can be added here
});
const app = new Koa().use(KoaLogger()).use(swagger({ exposeSpec: true }));

if (!isProduct) app.use(mocker());

useKoaServer(app, { ...router, cors: true });

console.time('Server boot');

app.listen(PORT, () => console.timeEnd('Server boot'));

Boot command

npx tsx index.ts

with Express

Just relpace useKoaServer() with useExpressServer() in routing-controllers & other equivalent middlewares for Express.