From 4c2f8426cd82becdad6f3d801330355019bc846b Mon Sep 17 00:00:00 2001 From: volatilization Date: Thu, 18 Apr 2024 03:11:07 +0300 Subject: [PATCH] update README.md with Client usage --- README.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7fa3a9f..5c29a01 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # objective-http Proxy classes for creating a http server -## Using +## Server + +There are all ```Server``` classes feature. +Your endpoints must implement ```Endpoint``` class interface (```route``` and ```handle``` functions). ``` javascript const http = require('node:http'); @@ -40,4 +43,40 @@ new ClusteredServer( cluster, {workers: workers_count} ).start(); +``` + +## Client + +``` javascript +const https = require('node:https'); +const { + OutputRequest, + InputResponse +} = require('objective-http').client; + + +const response = await new OutputRequest( + https, + new InputResponse(), + { + url: 'https://example.com', + method: 'POST', + body: 'test body' + }) + .send(); + +console.log(response.body().toString()); + +//or + +const request = new OutputRequest(https, new InputResponse()); + +const otherResponse = await (request + .copy({ + url: 'https://example.com', + method: 'POST', + body: 'test body' + })) + .send() + ``` \ No newline at end of file