How to use the midway.post function in midway

To help you get started, we’ve selected a few midway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alibaba / ice / packages / ice-midway-template / templates / server / src / app / controller / user.ts View on Github external
@inject('userService')
  service: IUserService;

  /**
   * GET /user/profile
   */
  @get('/profile')
  async profile(ctx) {
    const res = await this.service.profile();
    ctx.body = res.data;
  }

  /**
   * POST /user/login
   */
  @post('/login')
  async login(ctx) {
    const { username, password } = ctx.query;

    if (username === 'admin' && password === 'admin') {
      ctx.body = {
        status: 200,
        statusText: 'ok',
        currentAuthority: 'admin',
      };
    } else if (username === 'user' && password === 'user') {
      ctx.body = {
        status: 200,
        statusText: 'ok',
        currentAuthority: 'user',
      };
    } else {
github alibaba / ice / packages / ice-midway-template / templates / server / src / app / controller / user.ts View on Github external
/**
   * POST /user/register
   */
  @post('/register')
  async register(ctx) {
    ctx.body = {
      status: 200,
      statusText: 'ok',
      currentAuthority: 'user',
    };
  }

  /**
   * POST /user/logout
   */
  @post('/logout')
  async logout(ctx) {
    ctx.body = {
      status: 200,
      statusText: 'ok',
      currentAuthority: 'guest',
    };
  }
}
github midwayjs / midway-examples / demo-sequelize-typescript / src / app / controller / post.ts View on Github external
@post('/update')
  async update(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
    ctx.body = await this.postService.update(
      id,
      ctx.request.body.updates,
    );
  }

  @post('/delete')
  async delete(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
    ctx.body = await this.postService.softDelete(id);
  }

  @post('/destroy')
  async destroy(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
    ctx.body = await this.postService.destroy(id);
  }
}
github midwayjs / midway-examples / demo-plugin-egg-swagger-doc / src / app / controller / api.ts View on Github external
* @description 注册用户,记录用户账户/密码/
     * @router post /api/doRegist
     * @request body registUserRequest *body    
     */
  @post('/doRegist')
  async doRegist() {
    this.ctx.body = 'doRegist' + await this.userService.getUser();
  }

  /**
  * @summary 用户登录
  * @description 用户登录
  * @router post /api/doLogin
  * @request body registUserRequest *body    
  */
  @post('/doLogin')
  async doLogin() {
    this.ctx.body = 'doLogin' + await this.userService.getUser();
  }

}
github alibaba / ice / packages / ice-midway-template / templates / server / src / app / controller / user.ts View on Github external
statusText: 'ok',
        currentAuthority: 'user',
      };
    } else {
      ctx.body = {
        status: 401,
        statusText: 'unauthorized',
        currentAuthority: 'guest',
      };
    }
  }

  /**
   * POST /user/register
   */
  @post('/register')
  async register(ctx) {
    ctx.body = {
      status: 200,
      statusText: 'ok',
      currentAuthority: 'user',
    };
  }

  /**
   * POST /user/logout
   */
  @post('/logout')
  async logout(ctx) {
    ctx.body = {
      status: 200,
      statusText: 'ok',
github midwayjs / midway-examples / demo-sequelize-typescript / src / app / controller / post.ts View on Github external
@get('/')
  async index(ctx) {
    const query = {
      limit: parseInt(ctx.query.limit, 10) || 10,
      offset: parseInt(ctx.query.offset, 10) || 0,
    };

    ctx.body = await this.postService.list(query);
  }

  @get('/find')
  async show(ctx) {
    ctx.body = await this.postService.find(parseInt(ctx.query.id, 10));
  }

  @post('/create')
  async create(ctx) {
    ctx.body = await this.postService.create(ctx.request.body);
  }

  @post('/update')
  async update(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
    ctx.body = await this.postService.update(
      id,
      ctx.request.body.updates,
    );
  }

  @post('/delete')
  async delete(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
github midwayjs / midway / packages / midway-init / boilerplate / midway-ts-ant-design-pro-boilerplate / boilerplate / server / src / app / controller / user.ts View on Github external
@inject('userService')
  service: IUserService;

  /**
   * GET /user/profile
   */
  @get('/profile')
  async profile() {
    const res = await this.service.profile();
    this.ctx.body = res.data;
  }

  /**
   * POST /user/login
   */
  @post('/login')
  async login() {
    const { username, password } = this.ctx.query;

    if (username === 'admin' && password === 'admin') {
      this.ctx.body = {
        status: 200,
        statusText: 'ok',
        currentAuthority: 'admin',
      };
    } else if (username === 'user' && password === 'user') {
      this.ctx.body = {
        status: 200,
        statusText: 'ok',
        currentAuthority: 'user',
      };
    } else {
github midwayjs / midway-examples / demo-plugin-egg-swagger-doc / src / app / controller / api.ts View on Github external
@controller('/api')
export default class APIController {

  @inject()
  ctx: Context;

  @inject()
  userService;

  /**
     * @summary 注册用户
     * @description 注册用户,记录用户账户/密码/
     * @router post /api/doRegist
     * @request body registUserRequest *body    
     */
  @post('/doRegist')
  async doRegist() {
    this.ctx.body = 'doRegist' + await this.userService.getUser();
  }

  /**
  * @summary 用户登录
  * @description 用户登录
  * @router post /api/doLogin
  * @request body registUserRequest *body    
  */
  @post('/doLogin')
  async doLogin() {
    this.ctx.body = 'doLogin' + await this.userService.getUser();
  }

}
github midwayjs / midway / packages / midway-init / boilerplate / midway-ts-ant-design-pro-boilerplate / boilerplate / server / src / app / controller / user.ts View on Github external
/**
   * POST /user/register
   */
  @post('/register')
  async register() {
    this.ctx.body = {
      status: 200,
      statusText: 'ok',
      currentAuthority: 'user',
    };
  }

  /**
   * POST /user/logout
   */
  @post('/logout')
  async logout() {
    this.ctx.body = {
      status: 200,
      statusText: 'ok',
      currentAuthority: 'guest',
    };
  }
}
github midwayjs / midway-examples / demo-sequelize-typescript / src / app / controller / post.ts View on Github external
@post('/create')
  async create(ctx) {
    ctx.body = await this.postService.create(ctx.request.body);
  }

  @post('/update')
  async update(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
    ctx.body = await this.postService.update(
      id,
      ctx.request.body.updates,
    );
  }

  @post('/delete')
  async delete(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
    ctx.body = await this.postService.softDelete(id);
  }

  @post('/destroy')
  async destroy(ctx) {
    const id = parseInt(ctx.request.body.id, 10);
    ctx.body = await this.postService.destroy(id);
  }
}

midway

A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade.

MIT
Latest version published 3 years ago

Package Health Score

60 / 100
Full package analysis