# Response

## [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) methods

See [here](https://unetworking.github.io/uWebSockets.js/generated/interfaces/httpresponse.html)

## Implemented methods

* send
* pipe
* json (same as send, but for compatibility we keep this method)
* sendFile
* redirect
* status
* writeHead
* cookie
* setCookie
* hasCookie
* removeCookie
* setHeader
* getHeader
* hasHeader
* removeHeader
* setHeaders
* writeHeaderValues
* writeHeaders
* type
* header

## Examples

### Cookie + JSON example

```javascript
app.get('/is_logged', async (req, res) => {
  const status = res.hasCookie('userId') ? 'success' : 'error';

  return res.send({ status });
});
```

### Redirect + Params example

```javascript
app.get('/user/:id/login', async (req, res) => {
  const { id } = req.params;

  const result = await db.getUser(id);

  return res.redirect(`/user/${id}/`);
});
```

### sendFile

{% hint style="info" %}
File should be on the same path where JS file is or you can try **Absolute path** for **stream/sendFile**
{% endhint %}

```javascript
app.get('/video.mp4', async (req, res) => {
  return res.sendFile('video.mp4');
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nanoexpress.js.org/routes/response.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
