Revolving Hearts Logo. Heartml Search ⌘K

JavaScript Backend

Integration Examples #

Astro #

// riding.ts
import type { APIRoute } from "astro";
import RideTheStreetcar from "@heartml/ride-the-streetcar-js";

const streetcar = RideTheStreetcar.dsl();

export const POST = (({ request }) => {
  return new Response(
    streetcar.ride(sc => {
      ...
    }),
    { headers: { 'Content-Type': 'text/html; charset=utf-8' } }
  )
}) satisfies APIRoute;

Fastify #

import Fastify from 'fastify'
import RideTheStreetcar from '@heartml/ride-the-streetcar-js'

const fastify = Fastify({
  // ...further setup...
})

// declare a route
fastify.post('/path/to/url', function (request, reply) {
  reply
    .type('text/html; charset=utf-8')
    .send(streetcar.ride(sc => {
      ...
    }))
})

Express #

import express from 'express';
import RideTheStreetcar from '@heartml/ride-the-streetcar-js';

const app = express();
// ...further setup...

app.post('/path/to/url', (req, res) => {
  res
    .set('content-type', 'text/html; charset=utf-8')
    .send(streetcar.ride(sc => {
      ...
    }));
});

Skip to content Close