{"id":21433849,"url":"https://github.com/shpingalet007/http-packet","last_synced_at":"2025-03-16T22:44:26.669Z","repository":{"id":45234078,"uuid":"322663480","full_name":"shpingalet007/http-packet","owner":"shpingalet007","description":"HTTP crossplatform request generator","archived":false,"fork":false,"pushed_at":"2023-02-04T14:26:05.000Z","size":41,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T04:37:50.313Z","etag":null,"topics":["http","https"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/http-packet","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shpingalet007.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-18T17:36:26.000Z","updated_at":"2023-08-10T14:38:51.000Z","dependencies_parsed_at":"2023-02-18T17:15:50.719Z","dependency_job_id":null,"html_url":"https://github.com/shpingalet007/http-packet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shpingalet007%2Fhttp-packet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shpingalet007%2Fhttp-packet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shpingalet007%2Fhttp-packet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shpingalet007%2Fhttp-packet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shpingalet007","download_url":"https://codeload.github.com/shpingalet007/http-packet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243945531,"owners_count":20372894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","https"],"created_at":"2024-11-22T23:30:36.199Z","updated_at":"2025-03-16T22:44:26.642Z","avatar_url":"https://github.com/shpingalet007.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-packet\n\n[![Build Status](https://travis-ci.com/Shpingalet007/http-packet.svg?branch=main)](https://travis-ci.com/Shpingalet007/http-packet)  \n[![Coverage Status](https://coveralls.io/repos/github/Shpingalet007/http-packet/badge.svg?branch=main)](https://coveralls.io/github/Shpingalet007/http-packet?branch=main)\n\nHTTP crossplatform request generator. It allows generating and parsing HTTP 1.1 requests. May be used with net.Socket or any other transport. Working on browser and node.\n\n## How to use\n### Creating instance\nFirst, we need create HttpPacket instance.\n\n    // Use import HttpPacket from '@shpingalet007/http-packet';\n    // or const HttpPacket = require('@shpingalet007/http-packet');\n    \n    const httpPacket = new HttpPacket(/* params object */);\nHttpPacket supports more options to be passed in constructor, but they would be described further. The only mandatory param is **url**.\n\nWhat we need to know is that there are default params set:\n\n    version: '1.1' | HttpVersions.v1_1              // Currently stable on HTTP 1.1\n    method: 'get' | RequestMethods.Get              // HTTP Method GET\n    encoding: 'text/plain' | Encodings.TextPlain    // Text plain\n\n### Generating HTTP request\n#### Example 1: Simple GET request\nThe library can produce HTTP requests as string or as Uint8Array binary.\n\n    const httpPacket = new HttpPacket({ url: 'http://example.net/' });\n    const httpRequest = httpPacket.generate('string');\n\nThis will produce GET request to http://example.net/ :\n\n    GET / HTTP/1.1\\r\\n\n    Host: example.net\\r\\n\n    \\r\\n\n\n#### Example 2: GET request with query params\nWe can specify query params with constructor setting **queryParams**, or they might be decoded from **url** setting if there are any.\n\n    const httpPacket = new HttpPacket({\n      url: 'http://example.net/',\n      queryParams: { testParam: 'This is just a test' }\n    });\n    const httpRequest = httpPacket.generate('string');\nAll **queryParams** would be urlencoded automatically. And as a result, we get next request:\n\n\tGET /?testParam=This%20is%20just%20a%20test HTTP/1.1\\r\\n\n\tHost: example.net\\r\\n\n\t\\r\\n\n#### Example 3: POST request with data in body\nIn this example we would change the HTTP method and set some data in body\n\n    const httpPacket = new HttpPacket({\n      method: 'POST',\n      url: 'http://example.net/',\n      body: {  \n\t    encoding: /* 'application/json' || Encodings.Json, */\n\t    content: { testParam: 'This is just a test' }\n\t  }\n    });\n    const httpRequest = httpPacket.generate('string');\n\nAnd we get next request:\n\n    POST / HTTP/1.1\\r\\n\n    Host: example.net\\r\\n\n    Content-Type: application/json\\r\\n\n    Content-Length: 35\\r\\n\n    \\r\\n\n    {\"testParam\":\"This is just a test\"}\n#### Example 4: Complex request\nAlright, here we would make a conclusion creating complex request with all settings available in HttpPacket library.\n\n\tconst httpPacket = new HttpPacket({  \n\t  version: HttpVersions.v2_0,  \n\t  authentication: {  \n\t    type: AuthTypes.Basic,  \n\t    credentials: { username: 'admin', password: '0000' },  \n\t  },  \n\t  method: RequestMethods.Post,  \n\t  url: 'http://example.net/',  \n\t  queryParams: {  \n\t    q1: 'test',  \n\t  },  \n\t  headers: {  \n\t    // 'X-Application': 'Browser',  \n\t    xApplication: 'Browser', // This will result in 'X-Application' header\n\t    _xApplication: 'Browser', // This will result in 'xApplication' header\n\t  },  \n\t  body: {  \n\t    encoding: Encodings.FormUrlencoded,  \n\t    content: {  \n\t      a: '100',  \n\t      b: '200',  \n\t    },  \n\t  },  \n\t});\n\nResulting in next packet:\n\n\tPOST /?q1=test HTTP/2.0\\r\\n\n\tHost: example.net\\r\\n\n\tContent-Type: application/x-www-form-urlencoded\\r\\n\n\tX-Application: Browser\\r\\n\n\txApplication: Test header\\r\\n\n\tAuthorization: Basic YWRtaW46MDAwMA==\\r\\n\n\tContent-Length: 11\\r\\n\n\t\\r\\n\n\ta=100\u0026b=200\n\n### HttpPacket settings\nSettings are passed on instance construction. Full list is next:\n\n    version: typeof HttpVersions (default: HttpVersions.v1_1)\n    authentication: AuthBasic | AuthBearer (default: null)\n\tmethod: typeof RequestMethods (default: RequestMethods.Get)\n\turl: string, (mandatory param)\n\tqueryParams: object, (default: null)\n\theaders: object, (default: null)\n\tbody: ApplicationJsonBody | FormDataBody | UrlencodedBody | TextPlainBody\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshpingalet007%2Fhttp-packet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshpingalet007%2Fhttp-packet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshpingalet007%2Fhttp-packet/lists"}