custom-http is a lightweight package that imitates the core functionality of the http module. It provides some essential classes and constants, making it easy to create HTTP servers and clients in your application.
npm i @kimyu0218/custom-httpThe HttpRequest class represents the request made by the client. It provides various methods to access information about the request.
import { HttpRequest } from '@kimyu0218/custom-http';
...
const req: HttpRequest = new HttpRequest(data);
const path: string = req.getPath();
const method: string = req.getMethod();The HttpResponse class represents the response that the server sends back to the client. It provides methods to set response headers and body.
import { HttpResponse } from '@kimyu0218/custom-http';
...
const res: HttpResponse = new HttpResponse(socket);
res.throwError(404).send();The METHODS is an object containing HTTP methods.
import { METHODS } from '@kimyu0218/custom-http';
console.log(METHODS.GET); // GETThe STATUS_CODES is an object containing HTTP status codes and their respective messages.
import { STATUS_CODES } from '@kimyu0218/custom-http';
console.log(STATUS_CODES[200]); // OKThe CONTENT_TYPE is an object representing different content types. Each content type corresponds to a specific file extension.
import { CONTENT_TYPE } from '@kimyu0218/custom-http';
console.log(CONTENT_TYPE.HTML); // text/htmlIt's important to note that this project is still in development. If you find any issues or have suggestions for improvements, feel free to open an issue.