# TixFactory.Http
Table of Contents
- Introduction
- Methods
- Client: Request object
- Client: Response object
- Client: Making a request
- Client: Http configuration
- Client: Socket configuration
- Server: Request object
- Server: Response object
Introduction
This is just an http module I made for personal use that I decided to make public, don't expect professional grade http requests. This http module is mostly a dummy. It does not yet respect any headers, will not follow redirects, and will not allow setting the follow headers:
- Content-Type
- ^ Will include when requestBody is present - is set to requestBody.length
- Host
- ^ Will always be included as the host But if it helps anyone that's great! Expect bad documentation.
Typical installation, and module usage. To install:
$ npm install tixfactory.http
To use:
var http = ;var httpClient = ; // Everything happens from an individual client
Will auto-handle cookies, and accept-encoding.
- ^ Documentation required
Methods
var http = ; var httpClient = ;httpClient; // Returns promise: .then(function(response){ ... }).catch(function(errors){ ... });httpClient; // Returns http.request preset with url, and queryParameters with method: GEThttpClient; // Returns http.request with preset url, and requestBody with method: POSThttpClient;httpClient; var httpServer = port;
Client request object
"url": "https://www.google.com" // Required "method": "GET" // Required "queryParameters": "a": "b" // Optional "port": 80 // Optional, will also pull from url or default based on protocol "isSecure": true // Optional, will default based on protocol (whether or not to use tls socket) "requestHeaders": name: "Hello" value: "world" ... // Optional, also accepts object: {"Hello": "world"} "requestBody": Buffer // Optional "cookieJar": cookieJarObject // Optional - See: https://www.npmjs.com/package/cookiejar
Client response object
"statusCode": 400 "statusText": "Bad Request" "headers": name: "Set-Cookie" value: "wat=who" ... "body": Buffer "contentType": "application/json" // Semi-formatted Content-Type response header (when provided by server) "responseJson": "x": "y" // Will be available if the contentType is Json, and it can be parsed from JSON. "responseText": "{\"x\":\"y\"}" // Will be available for some known UTF-8 types.
Making a request
var http = ;var httpClient = ;httpClient;
The same request can also be made with:
var http = ;var httpClient = ;httpClient;
Client http configuration
var http = ;var httpClient = ;var currentConfiguration = httpClient;console;
Configuration object:
"cookieJar": cookieJarNpmObject "userAgent": "TixFactory.Http (node.js)" // This will be added automatically to any requests that do not have a User-Agent request header. Can be overriden by just setting it.
Mostly works like socketConfiguration, may or may not right documentation for this method at some point.
Client socket configuration
This module allows for some configuration around sockets including throttling and socket limits. To get current configuration settings:
var http = ;var httpClient = ;var currentConfiguration = httpClient;console;
Current configuration will look along the lines of:
"expiration": 30000 // How long a socket will remain open before closing from inactivity. "timeoutBetweenQueueProcessing": 50 // If a request is attempting to be made, but all the sockets are in use, and no more can be created: how long to wait before re-checking. , // This function should return how many writes per second the module is allowed to make per the arguments. Default returns 1000. MUST return number always. "getMaxSockets": function(host, port, isSecure) // This is how many sockets are allowed to be open per host (domain), port, and whether or not the socket type is tls. Defaults to 6. MUST return number always.}
To set configuration:
var http = ;var httpClient = ;httpClient
You only have to specify the fields you would like to override. For best results: setting configuration should only be done when the process starts.
Server request object
TODO: Document better
"ip": "127.0.0.1" // The remote IP address "method": "GET" // The request method "headers": name: "Hello" value: "world" ... // The request headers "headerMap": "hello": "world" // The request headers in object format (names are all lowercase) url: "pathname": "/" // [node URL object](https://nodejs.org/api/url.html) "queryParameters": name: "A" value: "b" ... // The query parameters "queryParameterMap": "a": "b" // The query parameters in object format(names are all lowercase) { ... } // Returns promise "body": Buffer // Will not be included if there is no response body
Server response object
TODO: Document better
"statusCode": 200 // The status response code (defaults to 200) "statusText": "OK" // The status description/text (defaults to [http.STATUS_CODES](https://nodejs.org/api/http.html#http_http_status_codes)) "body": Buffer // The response buffer "headers": name: "Hello" value: "world" ... // The response headers (can be array or object)
Server example
TODO: documentation wya?
var http = ;var httpServer = 80;httpServer;