Updated readme and quide
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
20fa35a575
commit
5120752ecb
52
README.md
52
README.md
@ -8,6 +8,7 @@
|
|||||||
- Docker
|
- Docker
|
||||||
- DroneCI
|
- DroneCI
|
||||||
- Lerna Support
|
- Lerna Support
|
||||||
|
- Support decorators
|
||||||
|
|
||||||
# Quickstart
|
# Quickstart
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ yarn start
|
|||||||
- Navigate
|
- Navigate
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
curl http://localhost:3000
|
curl http://localhost:3000/info
|
||||||
```
|
```
|
||||||
|
|
||||||
- Response
|
- Response
|
||||||
@ -33,6 +34,55 @@ curl http://localhost:3000
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Quick Register Controller
|
||||||
|
|
||||||
|
- Add new controller `src/controller/home.controller.ts`
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Request, Response } from "express"
|
||||||
|
import Controller from "../decorators/controller.decorator"
|
||||||
|
import { Get, Post } from "../decorators/handlers.decorator"
|
||||||
|
|
||||||
|
const data: any[] = []
|
||||||
|
|
||||||
|
@Controller("/home")
|
||||||
|
export default class HomeController {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
public get(req: Request, res: Response) {
|
||||||
|
res.json(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public create(req: Request, res: Response) {
|
||||||
|
const body = req.body
|
||||||
|
if (body == null) {
|
||||||
|
return res.status(400).json({
|
||||||
|
status: 400,
|
||||||
|
message: "Data is required",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
data.push(body)
|
||||||
|
res.json({
|
||||||
|
message: "Data created successfully",
|
||||||
|
body: body,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Register controller into index.ts `(src/controllers/index.ts)`
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import IndexController from "./index.controller"
|
||||||
|
import PersonController from "./person.controller"
|
||||||
|
import HomeController from "./home.controller"
|
||||||
|
|
||||||
|
export const controllers = [IndexController, PersonController, HomeController]
|
||||||
|
```
|
||||||
|
|
||||||
### Contributors
|
### Contributors
|
||||||
|
|
||||||
- Sambo Chea <sombochea@cubetiqs.com>
|
- Sambo Chea <sombochea@cubetiqs.com>
|
||||||
|
Loading…
Reference in New Issue
Block a user