HTTP Fundamentals

Request & response

Read request input and return JSON, redirects, cookies, files, streams, or views.

Beta · v0.2.0Lanjit APIs may change before the stable release. Review the release notes and upgrade guide before updating.

Each handler receives a Request and may use a Response. Requests expose method, URL, path, query parameters, route parameters, headers, cookies, and the original Node.js request. JSON, URL-encoded forms, and text bodies are supported with a configurable size limit.

Examples

Route.post('/profile/{user}', async (request, response) => {
  const userId = request.params.user;
  const page = request.input('page', 1);
  const token = request.header('authorization');
  const sessionId = request.cookies.lanjit_session;
  const payload = await request.all();

  return response.json({ userId, page, token, sessionId, payload });
});
const body = await request.body();
response.status(201).json({ created: true });
response.header('X-Request-Id', requestId).send('Selesai');
response.redirect('/dashboard');
response.cookie('theme', 'dark', {
  maxAge: 60 * 60 * 24 * 30,
  secure: true,
  sameSite: 'Lax',
});

response.forgetCookie('theme');
response.download(app.path('storage/app/report.pdf'), 'laporan.pdf');
response.stream(readable, 'text/csv; charset=utf-8');
Edit this page on GitHub

Type to search all documentation.