KScript docs
EN

Routes and APIs

Introduction

KScript.Http turns kscript serve into a server framework. A route file maps HTTP methods and paths to controllers. A controller is an ordinary fn that returns a view, JSON or a response. Middleware runs around controllers, for logging, CORS, sign-in, rate limits or checks of your own.

Pages you already have keep working. kscript serve sends each request to the routes first, and anything no route matches goes on to the site's pages and files.

CommandWhat it does
kscript serve samples/http-appServe the sample, then open http://localhost:8080/people.
kscript routes samples/http-appPrint the route table.
kscript openapi samples/http-appPrint the OpenAPI document made from the routes.

samples/http-app is a complete site with web routes, API routes, a controller, views, custom middleware and a kscript.json.

Edit this page on GitHub