Install package using:
npm i your-http
or
yarn add your-http
const http = require('your-http');
import http from 'your-http';
const http = require('your-http');
const router = new http.Router();
router.get('/', (req, res, next) => {
/* Code... */
});
exports.default = router;
import { Router } from 'your-http';
const router = new Router();
router.get('/', (req, res, next) => {
/* Code... */
});
export = router;
router.get('/', (req, res, next) => {});
.get(), .post(), .delete(), .put(), .update()
req, res, next
How to use it: Click here
Value | Description | Type |
---|---|---|
socket | TCP socket | Socket |
headers | Returns all headers | Object Property |
rawHeaders | All raw headers | Array |
protocol | Request HTTP protocol | string |
method | Request method | string |
url | Request endpoint | string |
body | Request body | any |
ip | Client IP | string |
query | Returns all query parameters | Object Property |
cookies | Returns all cookies | Object Property |
req.headers;
req.rawHeaders;
req.body;
req.ip;
req.query;
req.cookies;
How to use it: Click here
Value | Description | Type |
---|---|---|
socket | TCP socket | Socket |
protocol | Response HTTP protocol (HTTP/1.1) | string |
statusCode | Response status code | number |
statusMessage | Response status message | string |
headers | Returns all headers | Object Property |
body | Response body | any |
server | Server name | string |
lastModified | Last change to the response | Date |
canBeSent, wasSent | Values used by the http server. | boolean |
status(number) | Change status code of the response | Function |
write(string) | Set content type to text and change response body | Function |
json(object) | Set content type to application/json and change response body | Function |
cookies | Returns all cookies | Object Property |
setCookie(name, value, settings: object) | Adds a cookie to the response headers | Function |
send(any) | Automatically sets content type and changes body | Function |
setHeaders(name, value) | Adds a response header | Function |
res.headers;
res.status(number);
res.write(string);
res.json(object);
res.send(any);
res.setCookie(name, value, settings);
res.setHeader(name, value);
DO NOT MANUALLY CHANGE RESPONSE INFORMATION. Use response functions instead ( All functions displayed above );
http.createServer(router1, router2...).listen(port, ip[optional], callback[optional]);
http.createServer(router1).listen(3000, '0.0.0.0', () =>
console.log('π on port 3000.'));
...
req.cookies;
...
...
res.setCookie('name', 'value', { Settings: true });
...
...
req.body;
...
...
res.functionName/* send or write or json or status */(value);
...
...
req.query;
...
...
req.headers;
...
...
res.setHeader('name', 'value');
...