The Rest Api
For this tutorial, we’ll use Express (Remult works with many JavaScript web frameworks including Express, Fastify, Next.js, Sveltekit, nuxt.js, Hapi, Hono, Nest, and Koa).
Open backend/index.ts and add the following lines to include the Task in the REST API:
import express from 'express'import { remultApi } from 'remult/remult-express'import { Task } from '../shared/Task.js'
export const app = express()export const api = remultApi({ entities: [Task],})app.use(api)Code Explanation
- We import the necessary
remultApimodule for integrating Remult with Express. - We import the
Taskentity from thesharedfolder. - We use the
remultApifunction to set up the Remult REST API and register theTaskentity in itsentitiesarray. - Finally, we tell Express to use the API with
app.use(api).
See that it works
Click on the Test the Api button in the preview window, you should see an empty JSON array in the result.
You can also open the
networktab in the developer tools and see the requests that are being sent to the nodejs server
Files
Preparing Environment
- Installing dependencies
- Starting http server