Context
dobs is built on top of a base server that implements middleware using Node’s http module.
This means the request and response instances passed to handlers support all features provided by Node http, along with additional custom utilities.
For details on how the context is implemented, refer to the source code.
- Response
| Section | Description |
|---|---|
| req.pathname | URL pathname |
| req.href | Full URL href |
| req.search | URLSearchParams instance |
| req.searchString | Raw search string |
| req.query | Parsed query object |
| req.URL | URL instance |
| req.rawBody | Raw request body string |
- Request
| Section | Description |
|---|---|
| res.status | Set HTTP status code |
| res.message | Set HTTP status message |
| res.type | Set Content-Type |
| res.redirect | Redirect to URL |
| res.set | Set headers |
| res.get | Get header |
| res.remove | Remove header |
| res.has | Check header existence |
| res.isWritable | Check writable state |
| res.send | Auto-detect and send data |
| res.text | Send plain text |
| res.json | Send JSON |
| res.html | Send HTML |
| res.sendFile | Send file |
#Request
#req.pathname
Type: string
Provides the URL pathname.
console.log(req.pathname);
// "/users/123"#req.href
Type: string
Provides the full URL href.
console.log(req.href);
// "http://localhost:3000/users/123?active=true"#req.search
Type: URLSearchParams
Provides the URL search parameters.
const active = req.search.get("active");
console.log(active);
// "true"#req.searchString
Type: string
Provides the raw search string (without "?").
console.log(req.searchString);
// "active=true&page=4"#req.query
Type: object
Returns the search parameters as a plain object.
console.log(req.query);
// { active: "true", page: "4" }#req.URL
Type: URL
Returns a URL instance built from the incoming request.
console.log(req.URL.hostname); // "localhost"
console.log(req.URL.pathname); // "/users/123"#req.rawBody
Type: string
Provides the raw request body as a string.
server.post("/submit", (req, res) => {
console.log(req.rawBody);
// "{ \"message\": \"hello\" }"
res.send("ok");
});If you need accurate and structured body parsing (e.g., JSON, form data), use an external middleware such as
body-parser.
#Response
The Response object extends Node’s native ServerResponse and provides additional helper methods commonly used in web frameworks.
These utilities help you set headers, send data in various formats, and manage response states more easily.
#res.status
Type: (statusCode: number) => this
Sets the HTTP status code.
res.status(404).send("Not found");#res.message
Type: (message: string) => this
Sets the HTTP status message.
res.status(400).message("Bad Request").send();#res.type
Type: (type: string) => this
Sets the Content-Type header.
Supports file extensions, short names, and full MIME types.
res.type(".json");
res.type("json");
res.type("application/json");#res.redirect
Type: (url: string) => this
Performs a 302 redirect to the given URL.
res.redirect("https://example.com");#res.set
Type: (field: string | Record<string, any>, value?: any) => this
Sets one or multiple response headers.
res.set("foo", "bar");
res.set({
"x-powered-by": "dobs",
"cache-control": "no-store",
});#res.get
Type: (field: string) => any
Gets the value of a response header.
console.log(res.get("content-type"));#res.remove
Type: (field: string) => this
Removes a header.
res.remove("x-powered-by");#res.has
Type: (field: string) => boolean
Checks if a header is already set.
if (!res.has("content-type")) {
res.type("text/plain");
}#res.isWritable
Type: () => boolean
Checks whether the response is still writable (not finished or closed).
if (!res.isWritable()) return;
res.send("ok");#Data Sending Methods
#res.send
Type: (data: any) => void
Automatically detects the data type and sends it with the appropriate Content-Type.
Supports:
string, Buffer, object, number, etc.
res.send("hello world"); // text
res.send({ ok: true }); // JSON
res.send(Buffer.from("hi")); // binaryIf you want to manually control output, use res.end() instead.
#res.text
Type: (data: any) => void
Sends raw text with Content-Type: text/plain.
res.text("plain text response");#res.json
Type: (data: any) => void
Sends JSON with Content-Type: application/json.
res.json({ user: "yo", id: 1 });#res.html
Type: (data: string) => void
Sends HTML with Content-Type: text/html.
res.html("<h1>Hello</h1>");#res.sendFile
Type: (file: string) => void
Sends a file from disk.
res.sendFile("./public/index.html");