Skip to content

Quick start

You can install Mapl from npm.

Terminal window
npm i @mapl/app

Create a new file and add the following code:

server.ts
import { jitc, router } from '@mapl/app';
// Create a router
const app = router()
// Add a route that matches GET requests to '/'
.get('/', () => 'Hi');
// Build the app
const result = await jitc(app);
// Export the function to be executed
export default { fetch: result.fetch };

Then run the file with Bun or Deno.

Terminal window
# Bun
bun server.ts
# Deno
deno serve server.ts --port 3000

And done! We just build a simple web server running on 127.0.0.1:3000.

Explanation

  1. First we create a router instance by calling router().

    const app = router();
  2. Then we add an endpoint that returns Hi as a response.

    const app = router()
    .get('/', () => 'Hi');

    You can return anything that is supported by the Response constructor, which includes string, ArrayBuffer, Blob, ReadableStream, …

    Chaining is also possible since every method returns the current app instance.

    const app = router()
    .get('/', () => 'Hi')
    .get('/hello', () => 'Hello');
  3. Then we use the compiler to create an object that contains a request handler.

    const result = await jitc(app);
    result.fetch; // This is the request handler
  4. Finally we export the function correctly for the runtime to execute.