(over 3 years ago)

Introducing `micro` 3.0.0

Kevin Roark (@kevin-roark)

We're excited to introduce micro 3.0.0. Install or upgrade to it with:

▲ npm install -g micro

Sending some data with the status code 200, a very common task for many microservices, is now even simpler with micro.

Before, you had to always use the send helper:

import { send } from 'micro';
export default async function (req, res) {
send(res, 200, 'Hello World');

But now, we also grab the return value and:

  • Write it out of if it's a String
  • JSON encode it if it's an object
export default function (req, res) {
return 'Hello World';

Which using ES6 syntax becomes:

export default (req, res) => 'Hello world'

Since micro is optimized for async functions, you can directly return a Promise:

export default (req, res) => db.users.find({})

Then with micro -p 3000 app.js you can start to use the service:

curl http://localhost:3000
// all of your users :)

A mere function can become an HTTP server. You can take any value-or-promise-returning functions from other contexts and turn them into endpoints with micro.

Read the micro docs here to learn more, and please contact us on Twitter at @zeithq with feedback and requests. Thank you, all love!