Express & Koa compatible middleware for GitHub RESTful API
SemVer | branch | status | language | framework | API schema |
---|---|---|---|---|---|
>=0.6 |
main |
✅developing | TypeScript | Express & Koa | Swagger |
<0.6 |
master |
❌deprecated | ECMAScript | Express | APIDoc |
OAuth 2.0 (Production Environment can be used for debugging of localhost
)
API Proxy (HTTP-only Cookie Session instead of Access Token is easy to use for Web front-end)
Wrapper APIs to get the Technique(Language) list of a User or Organization
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)
One Hook URL to receive all kinds of Event
3 APIs of Server-sent events about Organization & Repository
The sample codes shown below will serve all the APIs of GitHub RESTful middleware with Koa, Swagger UI + JSON spec & Mock APIs.
npm i github-restful-middleware koa koa-logger koa2-swagger-ui koagger routing-controllers
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'));
npx tsx index.ts
Just relpace useKoaServer()
with useExpressServer()
in routing-controllers
& other equivalent middlewares for Express.