RunKit Endpoint Build APIs without any servers

Note: This is a beta release! We may make changes as Endpoint develops.


Endpoint is a fast and simple way to write code with Node.js that can respond to HTTP requests from anywhere. There's no need to manage servers or deployments, instead just write code in RunKit. Getting started is as easy as implementing one function. Here's a simple example:

exports.endpoint = function(request, response) { response.end("Hello world!"); }

The code above is now a real running endpoint. Changes will be reflected in real time. And just like with any notebook, you can (and should!) publish permanent versions as you develop your APIs. Go ahead, try curling it:


The Details

Any RunKit document that exports a function called endpoint can serve requests. The function should have the same signature as the callback passed to server.listen in node directly. The only change here is removing the explicit server creation and port binding.

exports.endpoint = function(request, response) {
    // your code goes here
}

URLs

Every RunKit Notebook has a main url like:

https://runkit.com/runkit/endpoint-demo-1

as well as specific revision URLs like:

https://runkit.com/runkit/endpoint-demo-1/branches/master
https://runkit.com/runkit/endpoint-demo-1/1.0.0

Accessing these notebooks from endpoint is as simple as replacing runkit.io for runkit.com. Unlike the main notebook page, which has a shorthand for accessing the latest revision, you'll just need to specifically reference /branches/master. Being explicit has an advantage; it means that not only will your notebook respond to urls like:

https://runkit.io/runkit/endpoint-demo-1/branches/master

It also responds to any sub-paths like these:

https://runkit.io/runkit/endpoint-demo-1/branches/master/hello/world
https://runkit.io/runkit/endpoint-demo-1/branches/master/use/the/force

You can use the enviroment variable process.env.RUNKIT_MOUNT_PATH to programatically check the base URL of your endpoint.

Logs of every request and response are available by clicking on the log icon on any notebook page. Logs are stored for 24 hours.


Examples

Simple JSON API

Want to build a simple API that sends/receives JSON messages, without dealing with HTTP at all? We built a simple helper for this that sets it up for you. You can see how the helper is implemented, or check out this usage example. You can also return a promise directly, or use a done callback.

var endpoint = require("@runkit/runkit/json-endpoint/1.0.0"); endpoint(exports, async function(incomingData) { var result = await doSomething(incomingData.body) return result })

Using Endpoint with Express

We've built a simple wrapper to set up a fully compatible Express app with Endpoint. Just require our wrapper instead of express, and pass in the exports object to your app constructor. You can see how the helper is implemented, or check out this usage example.

var express = require("@runkit/runkit/express-endpoint/1.0.0"); var app = express(exports); app.get("/:name", (req, res) => res.send(`hey ${req.params.name}`))

Restrictions

The main restriction is that cookie headers will be filtered out of requests and responses. This is to prevent malicious endpoints from attempting to attack other endpoints that might insecurely use cookies. Certain other security related headers are also filtered. Endpoint is only available over https.

Although RunKit let's you use a top level await at any time, you can't use a top level await before exporting your endpoint function.

Requests must terminate within 60 seconds. Endpoints are rate limited, and during the beta period they are restricted to non-commercial use. If you need to raise rate limits, or would like to use Endpoint commercially, just get in touch.