@stackpress/ingest
TypeScript icon, indicating that this package has built-in type declarations

0.1.22 • Public • Published

ᗊ Ingest

An unopinionated event driven serverless framework.

Install

$ npm install @stackpress/ingest

Usage

  1. Create an entry file called entry.ts
// entry.ts
import { task } from '@stackpress/ingest/dist/helpers';

export default task(function UserDetail(req, res) {
  //get params
  const ctx = req.ctxFromRoute('/user/:id');
  const id = ctx.params.get('id');
  if (!id) {
    res.code = 400;
    res.status = 'Bad Request';
    res.body = { error: 'ID is required' };
    return;
  }
  //maybe get from database?
  const results = { 
    id: id, 
    name: 'John Doe', 
    age: 21, 
    created: new Date().toISOString() 
  };
  //send the response
  res.mimetype = 'text/json';
  res.body = results;
});
  1. Create a server file called server.ts
// server.ts
import path from 'path';
import http from '@stackpress/ingest/http';

const server = http({ minify: false });
server.get('/user/:id', path.resolve(__dirname, 'user/detail'));

server.develop().listen(3000, () => {
  console.log('Server is running on port 3000');
  console.log('------------------------------');
  console.log(server.router.listeners);
});

/@stackpress/ingest/

    Package Sidebar

    Install

    npm i @stackpress/ingest

    Weekly Downloads

    517

    Version

    0.1.22

    License

    Apache-2.0

    Unpacked Size

    99 kB

    Total Files

    61

    Last publish

    Collaborators

    • cblanquera