Path

Path or pathname is an identifier to locate resources from a server.

http://localhost:8080/path/page

Teakit uses the path and method to look up the correct resource.

URL Representation

A path starts after the origin. Prefix with / and ends before search query (?)

We can categorize the URL and path as follows:

URL Path
http://site.com/
/
http://site.com/hello
/hello
http://site.com/hello/world
/hello/world
http://site.com/hello?name=salt
/hello
http://site.com/hello#title
/hello

If the path is not specified, the browser and web server will treat the path as '/' as a default value.

Teakit will lookup each request for route and response using handler function.

Dynamic path

URLs can be both static and dynamic.

Static path means a hardcoded string can be used to locate resources from the server while dynamic path matches some part and captures the value to extract extra information.

For instance, we can extract the user ID from the pathname, we can do something like:

import { Application } from "@teakit/core";
new Application().get("/id/:id", ({ params: { id } }) => id).listen(3000);

We create a dynamic path with /id/:id which tells Teakit to match any path up until /id and after it could be any value, which is then stored as params object.

When requested, the server should return the response as follows:

Path Response
/id/1
1
/id/anything
anything
/id/anything?name=salt
anything
/id
Not Found
/id/anything/rest
Not Found

Dynamic path is great to enforce the URL to contain crucial information like ID which then can be used later.

We refer to the named variable path as path parameter or params for short.

Segment

URL segment is each path that is composed into a full path.

Segment is separated by /.

Path parameters in Teakit are represented by prefixing a segment with ':' followed by a name.

Path parameters allow Elysia to capture a specific segment of URL.

The named path parameter will then be stored in Context.params.

Route Path Params
/id/:id
/id/1
id=1
/id/:id
/id/hi
id=hi
/id/:name
/id/hi
name=hi
PreviousRoute