github-restful-middleware
v1.0.0-rc.1
Published
Express & Koa compatible middleware for GitHub RESTful API
Downloads
6
Maintainers
Readme
GitHub-RESTful-middleware
Express & Koa compatible middleware for GitHub RESTful API
Version
| SemVer | branch | status | language | framework | API schema |
| :-----: | :------: | :----------: | :--------: | :-----------: | :--------: |
| >=0.6
| main
| ✅developing | TypeScript | Express & Koa | Swagger |
| <0.6
| master
| ❌deprecated | ECMAScript | Express | APIDoc |
Feature
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
withAccept: 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
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.