1.2.4 • Published 4 years ago

uno-api v1.2.4

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

uno-api

npm version build status install size npm downloads

simplify express router

#What's New in 1.2.0

  • getAllRoutes, for get all list route in uno-api

Boilerplate Uno-Api

This boilerplate using uno-api, you can learn here how to use uno-api

Thanks To: masb0ymas

installing

$ npm install uno-api

Example

var router = express.Router();
const UnoRouter = require('uno-api').Router
const simpleRouter = new UnoRouter(router)
const MiddlewareAuth = require('./controllers/MiddlewareAuth')
const UserController = require('./controllers/UserController')
function mainPage(req, res, next) {
  res.render('index', { title: 'Express' });
}

simpleRouter.create({
	baseURL: '/user',
	get: UserController.getUser,
	getWithParam: [
		[':UserId', UserController.getUserByUserId], //ex: http://localhost:3000/user/1
		[':UserId/:RoleId', MiddlewareAuth.main, UserController.getUserByRoleId] //ex: http://localhost:3000/user/1/5
	],
	post: {
		middleware: MiddlewareAuth.multer([{ name: 'file', maxCount: 1 }]), //or with array [MiddlewareAuth.multer([{ name: 'file', maxCount: 1 }])],
		callback: UserController.createUser
	},
	put: UserController.updateUser,
	delete: UserController.deleteUser,
})

unoAPI

KeyTypeObject Key
RouterFunctionconfigRouter
OPTIONSObject

unoApi.Router(config)

config

KeyTypeDesc
titlestringtitle for getAll
baseURLstringbaseURL for this Router
middlewarefunction, array functionmiddleware for this Router
wrapperRequestfunctionwrapperRequest / wrapper callback
//example

const simpleRouter = new unoApi.Router({
	title: 'RoutePublic', // this is grouping name routes for getAllRoutes
	baseURL: '', // you can define global baseURL here for this route
	middleware: [Middleware1, Middleware2], // you can define middleware here
	wrapperRequest: wrapperApiPublic // handle all callback by this function, ex: wrapperApiPublic(callback)
})

.Router API

KeyTypeDesc
getAllRoutesstatic functionto get all Routes Uno-Api
createfunctionto create route

simpleRouter.create(createConfig)

create config

KeyTypeDesc
titlestringgrouping name for getAllRoutes
baseURLstringurl API
getfunction, array function, objectget method
getWithParamarrayget method
postfunction, array function, objectpost method
postWithParamarraypost method
putfunction, array function, objectput method
putWithParamarrayput method
deletefunction, array function, objectdelete method
deleteWithParamarraydelete method
middlewarefunction / array functionmiddleware
overrideMiddlewarebooleanoverride middleware UnoApi.Router
wrapperRequestfunctionwrapperRequest / wrapper callback
simpleRouter.create({
    title: 'ApiMasterData',
    baseURL: '/master',
    get: myGetFunction, 
    post: [myMiddlewarePost, myPostFunction],
    put: {
      middleware: [myMiddlewarePut],
      callback: myPutFunction,
      overrideMiddleware: true
    },
    delete: [myMiddlewareDelete, myDeleteFunction, UnoApi.OPTIONS.OVERRIDE_MIDDLEWARE], // like put
    getWithParam: [
      [':id', myMiddlewareGetParam, myGetParamFunction], //ex: http://example.com/master/1
      [':id/:userid', myMiddlewareGetParam, myGetParamFunction, UnoApi.OPTIONS.OVERRIDE_MIDDLEWARE], //ex: http://example.com/master/1/299
      ['detail', myMiddlewareGetParam, myGetParamFunction, UnoApi.OPTIONS.OVERRIDE_MIDDLEWARE], //ex: http://example.com/master/detail
    ], // this config same for all route method get, post, put, delete (withParam)
    middleware: [MiddlewareMasterData],
    overrideMiddleware: true, // this will remove all UnoApi.Router middleware only for this API
    wrapperRequest: wrapperRequestMaster // wrapperRequest only for this API master, this will replace wrapperRequest UnoApi.Router
})

method config

method config

KeyTypeDesc
callbackfunctioncallback method
middlewarefunction / array functionmiddleware
overrideMiddlewarebooleanoverride middleware UnoApi.Router and .create
wrapperRequestfunctionwrapperRequest for this method only
simpleRouter.create({
	baseURL: '/public',
	get: {
            middleware: myGetMiddleware,
            callback: myGetFunction,
            overrideMiddleware: true,
            wrapperRequest: wrapperRequestMethod //
	},
	put: {
            middleware: myPutMiddleware,
            callback: wrapperRequestMethod(myPutFunction), //this is same like using wrapperRequest
            overrideMiddleware: true,
	}
})
1.2.4

4 years ago

1.2.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago