{"id":21948723,"url":"https://github.com/nemtsov/express-partial-response","last_synced_at":"2025-04-06T19:11:24.143Z","repository":{"id":9517964,"uuid":"11415517","full_name":"nemtsov/express-partial-response","owner":"nemtsov","description":"Express middleware for filtering-out parts of JSON responses based on the `fields` query-string; à la Google API's Partial Response.","archived":false,"fork":false,"pushed_at":"2021-07-07T10:14:20.000Z","size":24,"stargazers_count":111,"open_issues_count":4,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T18:09:57.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"nandarustam/fcm-push","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nemtsov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-15T05:30:33.000Z","updated_at":"2024-10-13T11:34:05.000Z","dependencies_parsed_at":"2022-07-13T07:20:30.112Z","dependency_job_id":null,"html_url":"https://github.com/nemtsov/express-partial-response","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fexpress-partial-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fexpress-partial-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fexpress-partial-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtsov%2Fexpress-partial-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nemtsov","download_url":"https://codeload.github.com/nemtsov/express-partial-response/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535517,"owners_count":20954576,"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-29T05:17:28.522Z","updated_at":"2025-04-06T19:11:24.122Z","avatar_url":"https://github.com/nemtsov.png","language":"JavaScript","funding_links":[],"categories":["中间件"],"sub_categories":[],"readme":"# Express Partial Response Middleware [![NPM version](https://badge.fury.io/js/express-partial-response.png)](http://badge.fury.io/js/express-partial-response)\n\nThis Express Middleware will allow you to send a subset of a JSON object\ninstead of the entire object from your HTTP services. To do so, your services\nwill begin accepting the `?fields=` query-string that, using a simple language,\nwill specify which fields and sub-fields to keep and which to ignore.\n\nIf you've used the Google APIs, provided a `?fields=` query-string to get a\n[Partial Response](https://developers.google.com/+/api/#partial-responses),\nand wanted to do the same for your own server, now you can do so with this\nmiddleware.\n\n_Underneath, this middleware uses [json-mask](https://github.com/nemtsov/json-mask).\nUse it directly without this middleware if you need more flexibility._\n\n# Installation\n\n```\nnpm install express-partial-response\n```\n\n# Usage\n\n```js\nconst express = require('express');\nconst partialResponse = require('express-partial-response');\nconst app = express();\n\napp.use(partialResponse());\n\napp.get('/', (req, res) =\u003e {\n  res.json({\n    firstName: 'Mohandas',\n    lastName: 'Gandhi',\n    aliases: [\n      {\n        firstName: 'Mahatma',\n        lastName: 'Gandhi'\n      },\n      {\n        firstName: 'Bapu'\n      }\n    ]\n  });\n});\n\napp.listen(4000);\n```\n\nLet's test it:\n\n```\n$ curl 'http://localhost:4000'\n{\"firstName\":\"Mohandas\",\"lastName\":\"Gandhi\",\"aliases\":[{\"firstName\":\"Mahatma\",\"lastName\":\"Gandhi\"},{\"firstName\":\"Bapu\"}]}\n\n$ # Let's just get the first name\n$ curl 'http://localhost:4000?fields=lastName'\n{\"lastName\":\"Gandhi\"}\n\n$ # Now, let's just get the first names directly as well as from aliases\n$ curl 'http://localhost:4000?fields=firstName,aliases(firstName)'\n{\"firstName\":\"Mohandas\",\"aliases\":[{\"firstName\":\"Mahatma\"},{\"firstName\":\"Bapu\"}]}\n```\n\n**Note:** take a look at `/example`.\n\n# Syntax\n\nLook at [json-mask](https://github.com/nemtsov/json-mask) for the available syntax of the `fields` param.\n\n# Options\n\n`query` specifies the query-string to use. Defaults to `fields`\n\n```js\napp.use(\n  partialResponse({\n    query: 'filter'\n  })\n);\n```\n\n# License\n\nMIT. See LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnemtsov%2Fexpress-partial-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnemtsov%2Fexpress-partial-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnemtsov%2Fexpress-partial-response/lists"}