How to use micro - 10 common examples

To help you get started, we’ve selected a few micro 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 DefinitelyTyped / DefinitelyTyped / types / micro / micro-tests.ts View on Github external
const bodyParsingHandler: RequestHandler = async (req, res) => {
    const buf = await buffer(req)
    console.log(buf)
    // 
    const txt = await text(req)
    // '{"price": 9.99}'
    const js: any = await json(req)
    // { price: 9.99 }
    console.log(js.price)
    return ''
}
github xkawi / micro-link / index.js View on Github external
async function onPost(req) {
  const data = await json(req);
  if (!data.web) {
    const error = new Error(
      `Please provide the web link as fallback url.`
    );
    error.statusCode = 400;
    throw error;
  }
  // TODO: take android package name
  const link = await generateDynamicLink(data);
  return { link };
}
github dangdennis / list / api / node / getWishes.js View on Github external
ddb.scan(params, function(err, data) {
    if (err) {
      send(res, 500, err);
    } else {
      // res.Items is returned as an array
      if (data.Items && data.Items.length) {
        // Unmarshall, aka reformat, the results to regular JSON format
        let unmarshalled = data.Items.map(item =>
          AWS.DynamoDB.Converter.unmarshall(item)
        );
        data.Items = unmarshalled; // We want to keep the other data points from DynamoDB
      }
      send(res, 200, data);
    }
  });
};
github Yoctol / bottender / packages / bottender-micro / src / verifyMessengerWebhook.js View on Github external
const verifyMessengerWebhook = ({ verifyToken }) => (req, res) => {
  const { query } = url.parse(req.url, true);
  if (
    query['hub.mode'] === 'subscribe' &&
    query['hub.verify_token'] === verifyToken
  ) {
    send(res, 200, query['hub.challenge']);
  } else {
    console.error('Failed validation. Make sure the validation tokens match.');
    send(res, 403);
  }
};
github coljs / workshop-microservices-micro / save / image-save.js View on Github external
module.exports = async function (req, res) {
  const body = await json(req)
  const { name, filter } = body

  let image, result
  try {
    image = await convert(name, filter)
    result = await s3move(name, image)
  } catch (e) {
    console.log(e.stack)
    return send(res, 500, e.message)
  }

  send(res, 200, { name: name, src: result.Location })
}
github zeit / micro / examples / json-body-parsing / index.js View on Github external
module.exports = async req => {
	const data = await json(req);
	console.log(data);

	return 'Data logged to your console';
};
github dangdennis / list / api / node / putWish.js View on Github external
ddb.putItem(params, (err, data) => {
      if (err) {
        console.log('Error', err);
        send(res, 500, err);
      } else {
        console.log('Success', data);
        send(res, 200, { ...data, user_id: uniqueId, name: data.name });
      }
    });
  } catch (e) {
github rockstat / front / src / http / http_server.ts View on Github external
private async parseBody(req: IncomingMessage, contentType?: string): Promise<[undefined, HTTPBodyParams] | [Error, undefined]> {
    let result: HTTPBodyParams;
    try {
      if (!contentType || !contentType.includes('json')) {
        result = parseQuery(await text(req, REQUEST_PARSE_OPTIONS));
      } else {
        result = await json(req, REQUEST_PARSE_OPTIONS);
      }
      return [undefined, isObject(result) ? result : {}];
    } catch (error) {
      return [error, undefined];
    }
  }
github rockstat / front / dist / http / http_server.js View on Github external
async parseBody(contentType, req) {
        let result;
        try {
            if (contentType.indexOf('json') >= 0) {
                result = await micro_1.json(req, parseOpts);
            }
            else {
                result = helpers_1.parseQuery(await micro_1.text(req, parseOpts));
            }
            return [undefined, helpers_1.isObject(result) ? result : {}];
        }
        catch (error) {
            return [error, undefined];
        }
    }
};
github rockstat / front / dist / http / http_server.js View on Github external
async parseBody(contentType, req) {
        let result;
        try {
            if (contentType.indexOf('json') >= 0) {
                result = await micro_1.json(req, parseOpts);
            }
            else {
                result = helpers_1.parseQuery(await micro_1.text(req, parseOpts));
            }
            return [undefined, helpers_1.isObject(result) ? result : {}];
        }
        catch (error) {
            return [error, undefined];
        }
    }
};

micro

Asynchronous HTTP microservices

MIT
Latest version published 2 years ago

Package Health Score

73 / 100
Full package analysis