Skip to content

shirohana/dynapi-example-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynapi-example-basic

Dynapi basic feature example

Live demo: https://dynapi.shirohana.me/example/basic

Demos

  • Basic usage of Responser, Middlewares, Parameter and Catcher
  • Create multi dynapi router on different root (In example: / & /api)
  • Aliases to shorter importings
  • Create a RESTful API

Directory structure

</dynapi-example-basic/server/
▾ api/
  ▾ user/
  |   >check-auth.js   <-- This will be invoked before following Responsers
  |   getPublic.js     <-- GET /api/user/public
  |   getSecret.js     <-- GET /api/user/secret
  |   postSignIn.js    <-- POST /api/user/sign-in
  |   postSignOut.js   <-- POST /api/user/sign-out
  |
  ▾ users/
  | ▾ :username/books/:bookId/
  | |   get.js         <-- GET /api/users/:username/books/:bookId
  | |                   '- One file alias: `get(users)(:username)(books)(:bookId).js`
  | |
  | | &bookId.js       <-- Validate `:bookId` in parent level
  | | &username.js     <-- Validate `:username` and fetch user information
  | |
  | #unauthorized.js   <-- Catch specific error (UserUnauthorizedError)
  | #user-not-found.js <-- Catch specific error (UserNotFoundError)
  | #~all.js           <-- Catch all unhandled errors
  | >init-helpers.js   <-- Middleware on root, all request will pass through this
  | getHelloWorld.js   <-- GET /api/hello-world
  |
▾ database/models/
  | user.js
  |
▾ errors/
  | user-not-found.js
  | user-unauthorized.js
  | user.js
  |
  index.js

Releases

No releases published

Packages

No packages published