1.0.0 • Published 5 years ago

@appengine/boat v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Boat Framework for API development

Rest API for Web and Mobile apps.

It features the following technologies:

How to run the server

Clone the repo

git clone https://github.com/chazeprasad/boat
npm install
gulp dev

How to create a CRUD API

Create a controller file under src/controller. eg: TodoController.ts

import { Request, Response, NextFunction } from 'express'
import { ActionController, Get, Api, Post, Put, Status } from "@appengine/airship";

@Api('/todo')
export class TodoController extends ActionController {
   
    constructor() {
        super();
        
    }

    @Post('/', [validateUser])
    async create(req:Request, res:Response, next:NextFunction) {
        res.status(Status.CREATED).json({
           task: 'Buy milk',
           done: false
        })
    }

    @Get('/')
    async index(req:Request, res:Response, next:NextFunction) {
       let todoList = [
           { todo: 'Stop working and enjoy the Holidays :-)', done: false },
           { todo: 'Eat food', done: false }
       ] 
        res.json({
            content: { todo: 'Stop working and enjoy the Holidays :-)', done: false }
        });

    }

    @Get('/:id')
    async show(req:Request, res:Response, next:NextFunction) {
        let id = request.params.id
        res.json({
            content: { todo: 'Stop working and enjoy the Holidays :-)', done: false },
        });
    }

    @Put('/:id')
    async update(req:Request, res:Response, next:NextFunction) {
        let id = request.params.id
        let userParams = req.body
        // Update
        res.sendStatus(Status.NO_CONTENT);
    }

    @Delete('/:id')
    async destroy(req:Request, res:Response, next:NextFunction) {
        let id = request.params.id
        let userParams = req.body
        // Delete
        res.sendStatus(Status.NO_CONTENT);
    }
}