How to use the micro.json function in micro

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 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 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];
        }
    }
};
github prismyland / prismy / packages / prismy / src / decorators / selectJsonBody.ts View on Github external
return createSelectDecorators((req, res) => {
    return json(req, options)
  })
}
github charliewilco / downwrite / app / export-md / index.js View on Github external
module.exports = cors(async (req, res) => {
  try {
    const js = await json(req)
    const content = createFile(js.title, js.content)

    res.setHeader('Content-Type', 'application/force-download')
    res.setHeader('Content-Disposition', `attachment; filename="${noSpace(js.title)}.md"`)

    send(res, 200, streamify(content))
  } catch (error) {
    sendError(req, res, error)
  }
})
github charliewilco / downwrite / app / export-json / index.js View on Github external
module.exports = cors(async (req, res) => {
  try {
    const js = await json(req)
    const content = createFile(js)

    res.setHeader('Content-Type', 'application/force-download')
    res.setHeader('Content-Disposition', `attachment; filename="${noSpace(js.title)}.json"`)

    send(res, 200, content)
  } catch (error) {
    sendError(req, res, error)
  }
})

micro

Asynchronous HTTP microservices

MIT
Latest version published 2 years ago

Package Health Score

72 / 100
Full package analysis