Browse Source

Add RESTful package to provide common details among services

dev
David Ludwig 4 years ago
parent
commit
79e7112968
3 changed files with 69 additions and 0 deletions
  1. +11
    -0
      packages/restful/package.json
  2. +51
    -0
      packages/restful/src/index.ts
  3. +7
    -0
      packages/restful/tsconfig.json

+ 11
- 0
packages/restful/package.json View File

@ -0,0 +1,11 @@
{
"name": "@autoplex/restful",
"version": "0.0.0",
"main": "dist/lib/index.js",
"types": "dist/typings/index.d.ts",
"license": "MIT",
"scripts": {
"build": "yarn run clean && tsc",
"clean": "rimraf ./dist"
}
}

+ 51
- 0
packages/restful/src/index.ts View File

@ -0,0 +1,51 @@
/**
* The basic response schema
*/
export interface IResponse<T> {
result?: T,
status : string
}
/**
* Supported status codes
*/
export enum Status {
Ok = 200,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
Conflict = 409,
Gone = 410,
PayloadTooLarge = 413,
UnprocessableEntity = 422,
InternalServerError = 500
}
/**
* Create a response
*/
export function statusMessage(status: Status): string {
switch(status) {
case Status.Ok:
return "OK"
case Status.BadRequest:
return "Bad Request";
case Status.Unauthorized:
return "Unauthorized";
case Status.Forbidden:
return "Forbidden";
case Status.NotFound:
return "Not Found";
case Status.Conflict:
return "Conflict";
case Status.Gone:
return "Gone";
case Status.PayloadTooLarge:
return "Payload Too Large";
case Status.UnprocessableEntity:
return "Unprocessable Entity";
case Status.InternalServerError:
return "Internal Server Error";
}
}

+ 7
- 0
packages/restful/tsconfig.json View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.package.json",
"compilerOptions": {
"outDir": "./dist/lib",
"declarationDir": "./dist/typings"
}
}

Loading…
Cancel
Save