{"id":15310397,"url":"https://github.com/abernier/uest","last_synced_at":"2025-04-15T01:08:05.050Z","repository":{"id":36797045,"uuid":"230288510","full_name":"abernier/uest","owner":"abernier","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-05T03:42:38.000Z","size":310,"stargazers_count":9,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T11:09:49.693Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/uest","language":"JavaScript","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/abernier.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":"2019-12-26T15:44:46.000Z","updated_at":"2022-05-03T12:50:46.000Z","dependencies_parsed_at":"2023-01-17T05:01:10.077Z","dependency_job_id":null,"html_url":"https://github.com/abernier/uest","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abernier%2Fuest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abernier%2Fuest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abernier%2Fuest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abernier%2Fuest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abernier","download_url":"https://codeload.github.com/abernier/uest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650508,"owners_count":21139678,"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":[],"created_at":"2024-10-01T08:28:06.074Z","updated_at":"2025-04-15T01:08:05.021Z","avatar_url":"https://github.com/abernier.png","language":"JavaScript","readme":"[![Build Status](https://github.com/abernier/uest/workflows/ci/cd/badge.svg)](https://github.com/abernier/uest/actions?query=workflow%3Aci%2Fcd)\n[![NPM version](https://img.shields.io/npm/v/uest.svg?style=flat)](https://www.npmjs.com/package/uest)\n![David](https://img.shields.io/david/abernier/uest)\n[![Coveralls github](https://img.shields.io/coveralls/github/abernier/uest)](https://coveralls.io/github/abernier/uest)\n\n`req.uest` is an Express middleware that allows you, from a given route, to request another route.\n\nFeatures are:\n- Initial `req` cookies are passed along to subsequent `req.uest`s\n- Cookies set by `req.uest`s responses are forwarded to initial `res`\n- `req.session` stay in sync between requests\n\nIt allows you to decouple your app's routes from your API's ones. IOW, your app routes can now consume your API as any client.\n\n## Install\n\n```\n$ npm i uest\n```\n\n```js\n// app.js\n\nconst uest = require('uest')\n\napp.use(uest())\n```\n\n## Usage\n\n```js\nreq.uest(options, (er, resp, body) =\u003e {})\n```\n\n- `options` -- are the same as [request/request](https://github.com/request/request#requestoptions-callback), with defaults to `json: true` and `baseUrl` to the same as your Express server.\n- `resp` -- the response object, see: [http.IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)\n  - **`resp.body`** holds the JSON response datas\n- `er` -- when an error occurs or `resp.statusCode \u003e= 400`, see: [http.ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest)\n  - **`er.status`** holds the response statusCode, for example: `404` or `409`...\n\nIt also supports `await`:\n\n```\nconst [resp, body] = await req.uest(options)\n```\n\n## Example\n\n```js\n// Mount our API router\napp.use('/api', require('./routers/api'));\n\n//\n// App routing\n//\n\napp.post('/login', (req, res, next) =\u003e {\n  const {email, password} = req.body\n\n  //\n  // Our subsequent request to `POST /api/sessions` route\n  //\n\n  req.uest({\n    method: 'POST',\n    url: '/api/sessions',\n    body: {email, password}\n  }, (er, resp, body) =\u003e {\n    if (er) {\n      // Deal with specific \"Forbidden\" error\n      if (er.status === 403) {\n        return res.render('login', {error: \"Wrong login/password\"})\n      }\n\n      return next(er); // for any other error\n    }\n\n    console.log('User-session created for', body.user)\n\n    // `req.session` is up-to-date\n    console.log(`Welcome back ${req.session.user.firstname}!`\n      \n    res.redirect('/profile')\n  })\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabernier%2Fuest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabernier%2Fuest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabernier%2Fuest/lists"}