How to use the @foal/core.HttpResponseOK function in @foal/core

To help you get started, we’ve selected a few @foal/core 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 FoalTS / foal / packages / acceptance-tests / src / csrf / regular-web-app.stateless.spec.ts View on Github external
async home(ctx: Context) {
      // Normally in an HTML template
      const response = new HttpResponseOK();
      setCsrfCookie(response, await getCsrfToken());
      return response;
    }
  }
github FoalTS / foal / packages / cli / src / generate / specs / rest-api / test-foo-bar.controller.ts View on Github external
async patchById(ctx: Context) {
    const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);

    if (!testFooBar) {
      return new HttpResponseNotFound();
    }

    Object.assign(testFooBar, ctx.request.body);

    await getRepository(TestFooBar).save(testFooBar);

    return new HttpResponseOK(testFooBar);
  }
github FoalTS / foal / packages / cli / src / generate / specs / rest-api / test-foo-bar.controller.current-dir.ts View on Github external
async putById(ctx: Context) {
    const testFooBar = await getRepository(TestFooBar).findOne(ctx.request.params.testFooBarId);

    if (!testFooBar) {
      return new HttpResponseNotFound();
    }

    Object.assign(testFooBar, ctx.request.body);

    await getRepository(TestFooBar).save(testFooBar);

    return new HttpResponseOK(testFooBar);
  }
github FoalTS / foal / packages / swagger / src / swagger-controller.ts View on Github external
getOpenApiDefinition(ctx: Context) {
    if (isUrlOption(this.options)) {
      return new HttpResponseNotFound();
    }

    if (!Array.isArray(this.options)) {
      const document = createOpenApiDocument(this.options.controllerClass, this.controllers);
      return new HttpResponseOK(document);
    }

    const name = ctx.request.query.name;
    if (typeof name !== 'string') {
      return new HttpResponseBadRequest('Missing URL parameter "name".');
    }

    const option = this.options.find(option => option.name === name);
    if (!option || isUrlOption(option)) {
      return new HttpResponseNotFound();
    }

    return new HttpResponseOK(createOpenApiDocument(option.controllerClass, this.controllers));
  }
github FoalTS / foal / packages / examples / src / app / controllers / product.controller.ts View on Github external
async putById(ctx: Context) {
    const product = await getRepository(Product).findOne(ctx.request.params.id);

    if (!product) {
      return new HttpResponseNotFound();
    }

    Object.assign(product, ctx.request.body);

    await getRepository(Product).save(product);

    return new HttpResponseOK(product);
  }