{"id":13448618,"url":"https://github.com/poppinss/request","last_synced_at":"2025-03-22T09:31:31.320Z","repository":{"id":57137678,"uuid":"186006045","full_name":"poppinss/request","owner":"poppinss","description":"Node.Js request wrapper used by AdonisJs framework","archived":true,"fork":false,"pushed_at":"2019-09-08T10:48:33.000Z","size":333,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-03-12T06:33:02.126Z","etag":null,"topics":["adonis","adonisjs","node-req"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poppinss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-10T14:52:34.000Z","updated_at":"2023-12-27T04:41:35.000Z","dependencies_parsed_at":"2022-08-22T20:50:14.293Z","dependency_job_id":null,"html_url":"https://github.com/poppinss/request","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Frequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Frequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Frequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poppinss%2Frequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poppinss","download_url":"https://codeload.github.com/poppinss/request/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244937751,"owners_count":20535124,"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":["adonis","adonisjs","node-req"],"created_at":"2024-07-31T05:01:50.711Z","updated_at":"2025-03-22T09:31:31.004Z","avatar_url":"https://github.com/poppinss.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://res.cloudinary.com/adonisjs/image/upload/q_100/v1557762307/poppinss_iftxlt.jpg\" width=\"600px\"\u003e\n\u003c/div\u003e\n\n# Request\n[![circleci-image]][circleci-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]\n\nWrapper over Node.js [req](https://nodejs.org/dist/latest/docs/api/http.html#http_class_http_incomingmessage) object to standardize and ease the process of reading data from HTTP requests.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n## Table of contents\n\n- [Features](#features)\n- [Usage](#usage)\n- [Config](#config)\n- [Typescript support](#typescript-support)\n- [API](#api)\n- [Maintainers](#maintainers)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Features\n1. Support for reading plain and signed cookies (only when signed via [@poppinss/response](https://github.com/poppinss/response))\n2. Handy methods for content negotiation.\n3. Handles inconsistencies between certain headers like `referer` and `referrer`.\n4. Reliably reads `ip address` of proxied requests.\n5. Assigns distributed unique `x-request-id` to each request.\n\n## Usage\nInstall the package from npm as follows:\n\n```sh\nnpm i @poppinss/request\n\n# yarn\nyarn add @poppinss/request\n```\n\nand then use it as follows\n\n```ts\nimport { Request, RequestConfigContract } from '@poppinss/request'\nimport { createServer } from 'http'\n\nconst config: RequestConfigContract = {\n  allowMethodSpoofing: false,\n  subdomainOffset: 2,\n  trustProxy: require('proxy-addr').compile('loopback'),\n}\n\ncreateServer((req, res) =\u003e {\n  const request = new Request(req, res, config)\n  res.end(`${request.id()} ${request.url()}`)\n})\n```\n\n## Config\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=\"2\"\u003e\u003ccode\u003e{\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"allowMethodSpoofing\": false\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cp\u003e\n      Since, standard HTML forms doesn't allow all HTTP verbs like \u003ccode\u003ePUT\u003c/code\u003e, \u003ccode\u003eDELETE\u003c/code\u003e and so on. The \u003ccode\u003eallowMethodSpoofing\u003c/code\u003e allows defining the HTTP method as a query string \u003ccode\u003e_method\u003c/code\u003e.\n      \u003c/p\u003e\n      \u003cp\u003e\n       When \u003ccode\u003eallowMethodSpoofing = true\u003c/code\u003e and current request method is POST, then \u003ccode\u003erequest.method()\u003c/code\u003e will give preference to the query string \u003ccode\u003e_method\u003c/code\u003e property, over the original request method.\n      \u003c/p\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"subdomainOffset\": 2\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cp\u003e\n      Offset indicates the number of values to remove from the end of the URL seperated by \u003ccode\u003e.\u003c/code\u003e.\n      \u003c/p\u003e\n      \u003cp\u003e\n      For example: For URL \u003ccode\u003eindicative.adonisjs.com\u003c/code\u003e, the \u003ccode\u003erequest.subdomains()\u003c/code\u003e method will return an array with \u003ccode\u003e['indicative']\u003c/code\u003e.\n      \u003c/p\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"trustProxy\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cp\u003e\n      A method that allows you to selectively trust the proxy servers. Make sure to read \u003ca href=\"https://www.npmjs.com/package/proxy-addr#proxyaddrcompileval\"\u003eproxy-addr docs\u003c/a\u003e.\n      \u003c/p\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"getIp\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cp\u003e\n      Optionally define a method to determine the user Ip adress. The method is helpful, when you want to rely on a different property to find the user ip address.\n      \u003c/p\u003e\n      \u003cp\u003e\n      For example: Nginx set \u003ccode\u003ex-real-ip\u003c/code\u003e header when used a proxy server.\n      In that case you can define your own \u003ccode\u003egetIp\u003c/code\u003e method for same.\n      \u003c/p\u003e\n      \u003cdiv class=\"highlight highlight-source-js\"\u003e\u003cpre\u003e\u003ccode\u003egetIp (request) {\n  // I am using nginx as a proxy server and want to trust 'x-real-ip'\n  return request.header('x-real-ip')\n}\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd valign=\"top\"\u003e\u003ccode\u003e\"secret\"\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\n      \u003cp\u003e\n      \u003cstrong\u003eOptional\u003c/strong\u003e Define a secret to unsign and read cookies. Make sure you have used the same secret to sign the cookie via \u003ca href=\"https://github.com/poppinss/response\"\u003e@poppinss/response\u003c/a\u003e package.\n      \u003c/p\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=\"2\"\u003e\u003ccode\u003e}\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Typescript support\nThe module is written in Typescript and exports following classes, types and interfaces.\n\n```ts\nimport { Request, RequestContract, RequestConfigContract} from '@poppinss/request'\n```\n\n**RequestContract** is the interface that `Request` class adheres too. Since, you cannot extend concrete implementations in Typescript, you may need the interface to have a lossely typed flow.\n\n```ts\nRequest.macro('cartValue', function () {\n  return Number(this.cookie('cart')) || 0\n})\n```\n\nthen, you need to add `cartValue` to the interface\n\n```ts\nimport { RequestContract as BaseContract } from '@poppinss/request'\n\ninterface RequestContract extends BaseContract {\n  cartValue (): number\n}\n\nconst request = new Request(req, res, config) as unknown as RequestContract\n```\n\n## API\nFollowing are the autogenerated files via Typedoc\n\n* [API](docs/README.md)\n\n## Maintainers\n[Harminder virk](https://github.com/thetutlage)\n\n[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/request/master.svg?style=for-the-badge\u0026logo=appveyor\n[circleci-url]: https://circleci.com/gh/poppinss/request \"circleci\"\n\n[npm-image]: https://img.shields.io/npm/v/@poppinss/request.svg?style=for-the-badge\u0026logo=npm\n[npm-url]: https://npmjs.org/package/@poppinss/request \"npm\"\n\n[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge\u0026logo=typescript\n\n[license-url]: LICENSE.md\n[license-image]: https://img.shields.io/aur/license/pac.svg?style=for-the-badge\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoppinss%2Frequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoppinss%2Frequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoppinss%2Frequest/lists"}