Content-Length: 68811 | pFad | https://dev.to/queentiol/response-methods-heo

7 Response methods - DEV Community

DEV Community

Sosanya Esther
Sosanya Esther

Posted on

Response methods

What are Response Methods?
The Response object (response) provides the HTTP response that an Express app sends when it receives an HTTP request.

Different Types of Response Methods
1.res.send(): Most people are already familiar with the res.send() method. You can answer HTTP requests with a variety of data types using res. send().
2.res.json(): It is used for sending a JSON response. This function uses JSON.stringify() to transform the parameter into a JSON string and sends a response (with the correct content type).
3.res.status(): Represents the status of the response, res. status defines the HTTP response code. If an unidentified status code is provided, the response body will just contain the code's numeric value.
Each code will represent a different response state.
-5xx: Server error
-4xx: Error in clients
-3xx: Redirects
-2xx: Success
-1xx : Information
4.res.download(): The file at the path is transferred as an "attachment." Browsers will typically prompt the user to download. The path argument is used by default to derive the Content-Disposition header "filename=" parameter, although this can be modified with the filename parameter. If the path is relative, it will be based on the process's current working directory or the root option, if specified.
5.res.end(): The response procedure will end using this method. This method was inspired by Node core, notably the response. end() method of HTTP.ServerResponse. Use to swiftly terminate the response with no data. If you want to send the response with data, instead use res. send() and res.json().
6.res.send file(): Transfers the file at the specified path. Sets the Content-Type response HTTP header field based on the extension of the filename. The path should be a complete path to the file unless the root option is provided in the options object.

Top comments (0)









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://dev.to/queentiol/response-methods-heo

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy