{"id":18391453,"url":"https://github.com/figadore/express-request-formatter","last_synced_at":"2025-04-12T09:39:39.849Z","repository":{"id":57358459,"uuid":"47853797","full_name":"figadore/express-request-formatter","owner":"figadore","description":"request/response formatter for node.js express apps","archived":false,"fork":false,"pushed_at":"2017-12-12T02:23:21.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T05:12:26.528Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/shiny-express-formatter","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/figadore.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":"2015-12-11T22:17:30.000Z","updated_at":"2017-12-12T02:23:22.000Z","dependencies_parsed_at":"2022-09-26T16:40:49.589Z","dependency_job_id":null,"html_url":"https://github.com/figadore/express-request-formatter","commit_stats":null,"previous_names":["shinymayhem/express-request-formatter"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/figadore%2Fexpress-request-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/figadore%2Fexpress-request-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/figadore%2Fexpress-request-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/figadore%2Fexpress-request-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/figadore","download_url":"https://codeload.github.com/figadore/express-request-formatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248548761,"owners_count":21122761,"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-11-06T01:51:54.683Z","updated_at":"2025-04-12T09:39:39.826Z","avatar_url":"https://github.com/figadore.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express Request/Response formatter\n\nFormats requests and responses, and optionally bodies, for logging. When capturing response bodies, it only handles non-streaming requests. It is up to the app to determine what to do with the formatted objects\n\nExample Request\n\n```\n{\n  \"id\": \"7d575f6b-cac9-43cc-96f2-7695f909819d\",\n  \"headers\": {\n    \"host\": \"localhost:3080\",\n    \"connection\": \"keep-alive\",\n    \"accept\": \"application/json, text/plain, */*\",\n    \"user-agent\": \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36\",\n    \"referer\": \"http://localhost:3080/\",\n    \"accept-encoding\": \"gzip, deflate, sdch\",\n    \"accept-language\": \"en-US,en;q=0.8\"\n  },\n  \"method\": \"GET\",\n  \"path\": \"/api/widgets\",\n  \"body\": {}\n}\n```\n\nExample Response\n\n```\n{\n  \"headers\": {\n    \"x-powered-by\": \"Express\",\n    \"content-length\": \"24\",\n    \"etag\": \"W/\\\"I4+1GQyv6zGcoXDQygDf+g==\\\"\"\n  },\n  \"requestId\": \"7d575f6b-cac9-43cc-96f2-7695f909819d\",\n  \"time\": 222,\n  \"status\": 200,\n  \"size\": 24,\n  \"body\": {\n    \"widgets\": [],\n    \"links\": []\n  }\n}\n```\n\n## Usage\nInclude the module\n\n`requestFormatter = require('shiny-express-formatter');`\n\nAdd middleware for formatting requests/responses\n\n`app.use(requestFormatter.formatRequests(options));`\n\nEnsure any request body parsing middleware (e.g. body-parser) is set prior to using the formatting middleware\n\n### Options\n* `onRequestCaptured`: function(requestLogObject). callback to run once request object has been formatted. Useful for capturing request id to set bunyan child loggers. default: do nothing\n\n* `onResponseCaptured`: function(requestLogObject, responseLogObject). callback to run once request and response objects have been formatted. default: do nothing\n\n* `captureRequestBody`: boolean|function(req). whether to include the request body in the callback. default: false. If set to a function, returned results will be the boolean that determines whether to capture the body (allows logging only json bodies, for example)\n\n* `captureResponseBody`: boolean|function(req, res). whether to include the response body in the callback. default: false. If set to a function, returned results will be the boolean that determines whether to capture the body (allows logging only json bodies, for example)\n\n* `logRequestHeaders`: boolean|function(req). whether to include the request body in the callback. default: true. If set to a function, returned results will be used as headers to log (allows filtering out sensitive headers)\n\n* `logResponseHeaders`: boolean|function(req, res). whether to include the response body in the callback. default: true. If set to a function, returned results will be used as headers to log (allows filtering out sensitive headers)\n\n### possible future work\n* add options to create conditions for which types of request/response bodies are captured (e.g. json only)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffigadore%2Fexpress-request-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffigadore%2Fexpress-request-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffigadore%2Fexpress-request-formatter/lists"}