How to use the midway.get 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 ykfe / egg-react-ssr / example / ssr-with-ts / src / app / controller / api.ts View on Github external
import { controller, provide, inject, Context, get } from 'midway'
import { IApiService } from '../../interface'
@provide()
@controller('/api')
export class Api {
  @inject()
    ctx: Context
  @inject('ApiService')
    service: IApiService
  @get('/getIndexData')
    async index () {
    try {
            // Page为webpack打包的chunkName,项目默认的entry为Page
      this.ctx.type = 'text/json'
      this.ctx.status = 200
      this.ctx.body = await this.service.index()
    } catch (error) {
      this.ctx.logger.error(`Page Controller renderToStream Error`, error)
    }
  }
}
github midwayjs / midway-examples / demo-extended-koa / src / app / controller / user.ts View on Github external
import { controller, get, inject } from 'midway';
import { IUserAbstract, IUserResult } from '../../lib/interfaces/user.abstract';

type nextDefinition = () => void;

@controller('/user/')
export class UserController {
  @inject('userService')
  service: IUserAbstract;

  @get('/:id')
  async getUser(ctx: any, next: nextDefinition): Promise {
    const id: number = ctx.request.params('id');
    const user: IUserResult = await this.service.getUser({id});
    ctx.body = {success: true, message: 'OK', data: user};
    // do not response again
    await next();
  }
}
github midwayjs / midway-examples / demo-unittest / src / app / controller / home.ts View on Github external
import { controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {

  @get('/')
  async index(ctx) {
    ctx.body = `Welcome to midwayjs!`;
  }
}
github midwayjs / midway-examples / demo-sequelize-typescript / src / app / controller / post.ts View on Github external
@controller('/post')
export class PostController {
  @inject()
  postService: IPostService;

  @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,
    );
github midwayjs / midway-examples / demo-extended-koa / src / app / controller / home.ts View on Github external
import { controller, get, provide, Context } from 'midway';

@provide()
@controller('/')
export class HomeController {

  @get('/')
  async index(ctx: Context) {
    ctx.body = ctx.getName() + ' ' + ctx.name;
  }

  @get('/api', {middleware: ['apiMiddleware']})
  async api(ctx: Context) {
    ctx.body = ctx.api;
  }

}
github midwayjs / midway-examples / demo-extended-koa / src / app / controller / home.ts View on Github external
import { controller, get, provide, Context } from 'midway';

@provide()
@controller('/')
export class HomeController {

  @get('/')
  async index(ctx: Context) {
    ctx.body = ctx.getName() + ' ' + ctx.name;
  }

  @get('/api', {middleware: ['apiMiddleware']})
  async api(ctx: Context) {
    ctx.body = ctx.api;
  }

}
github midwayjs / midway / packages / midway-init / boilerplate / midway-ts-ant-design-pro-boilerplate / boilerplate / server / src / app / controller / home.ts View on Github external
import { Context, inject, controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {

  @inject()
  ctx: Context;

  @get('/')
  async index() {
    await this.ctx.render('index');
  }
}
github midwayjs / midway-examples / demo-plugin-schedule / src / app / controller / home.ts View on Github external
import { controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {

  @get('/')
  async index(ctx) {
    ctx.body = `Welcome to midwayjs!`;
  }
}
github midwayjs / midway-examples / demo-sequelize / src / app / controller / post.ts View on Github external
* - https://github.com/midwayjs/midway-examples/tree/master/demo-sequelize
 * - http://docs.sequelizejs.com/manual/typescript.html
 */
import { controller, del, get, inject, patch, post, provide } from 'midway';
import { IPostService } from '../../interface';

@provide()
@controller('/post/')
export class PostController {
  @inject('postService')
  public service: IPostService;

  /**
   * GET /post
   */
  @get('/')
  public async index(ctx) {
    const query = {
      limit: parseInt(ctx.query.limit, 10) || 10,
      offset: parseInt(ctx.query.offset, 10) || 0,
    };
    ctx.body = await this.service.list(query);
  }

  /**
   * GET /post/:id
   */
  @get('/:id')
  public async show(ctx) {
    ctx.body = await this.service.find(parseInt(ctx.params.id, 10));
  }
github alibaba / ice / packages / ice-midway-template / templates / server / src / app / controller / home.ts View on Github external
import { controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {
  @get('/')
  async index(ctx) {
    await ctx.render('index.ejs', {
      assets: ctx.assets,
    });
  }
}

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