0.0.2 • Published 8 months ago
jsonapi-check v0.0.2
jsonapi-check
Easy to check type for json api response. Auto generate TypeScript schema file by request info ( path, method and response ) at first time, then check json response according to the associated TypeScript schema next request. Of course, the TypeScript schema files can be rewritten.
Install
npm install jsonapi-check -D
Usage
axiosnode
See example/node for more details.
import { jsonapiCheck } from 'jsonapi-check'
axios.interceptors.response.use((response) => {
const { request, data } = response
const { path, method } = requset
const options = {
schemaDir: 'schema',
hasSubdirs: false
}
// dev-mode check
jsonapiCheck(path, method, data, options)
return response
})
fetchbrower
See example/brower for more details.
RESTful API
- GET /authors --> schema/authors-GET.ts --> interface Author
- GET /authors/12 --> schema/author-GET.ts --> interface Author
Options
schemaDir
- Type:
string
Default:
schema
The name of directory for generate json schema type.
hasSubdirs
- Type:
boolean
Default:
false
The schema directory has subdirectory or not. If true, will mkdir like next directory.
GET /authors --> schema/authors/authors-GET.ts --> interface Author
- GET /web/…/authors --> schema/web/author-GET.ts --> interface Author
License
MIT License © 2023-Present Efrice.