memo-api
v1.0.1
Published
A simple dynamic routing web framework.
Downloads
92
Readme
Table of contents
// index.js
const MemoApi = require('./src/core')
const app = new MemoApi()
app.get('/', function (req, res) {
res.end('Hello World')
})
app.listen({ port:4000 })
Installation
Before installing, download and install Node.js. Node.js 0.10 or higher is required.
If this is a brand new project, make sure to create a package.json
first with
the npm init
command.
Installation is done using the
npm install
command:
$ npm install memo-api
Configure
app.listen({
// listen port
port:4000,
// console log
logger:true,
// domain whitelist
hosts:["localhost:4000","192.168.10.123"],
// body max size
limit: 10000
})
Dynamic Routing
It should be noted that routing has an execution order, from front to back
app.get('/user/:name', function (req, res) {
const { name } = req.params
// "/user/rainto?id=123456"
// If there are parameters like 'id' in the link
const { id } = req.query
res.end(`Hello ${name}` )
})
Verify schema
The schema validation method is more like Fascify.
const schema = {
body: {
name:{
type: String
// default
default: "rainto"
},
email: {
// type
type: String,
// regular expression
RegExp: /^[^\s@]+@[^\s@]+\.[a-zA-Z0-9]+(\.[a-zA-Z]{2,})?$/,
// [minLength,maxLength]
length: [8,25]
},
},
// required options
require:["email"]
}
app.post('/',(req,res)=>{
res.end(JSON.stringify(req.body))
},{ schema: signup_schema })