Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
express-partial-hal-response
Advanced tools
Express middleware for filtering-out parts of HAL+JSON responses based on the `fields` query-string.
This Library is strongly influenced by express-partial-response.
This Express Middleware will allow you to send a subset of a HAL+JSON object
instead of an entire object from your HTTP services. To do so, your services
will begin accepting the ?fields=
query-string that, using a simple language,
will specify which fields and sub-feelds to keep and which to ignore.
If you've used the Google APIs, provided a ?fields=
query-string to get a
Partial Response,
and wanted to do the same for your own server, now you can do so with this
middleware.
Underneath, this middleware uses json-mask. Use it directly without this middleware if you need more flexibility.
npm install express-partial-hal-response
var express = require('express')
, partialHalResponse = require('express-partial-hal-response')
, app = express()
app.use(partialHalResponse())
app.get('/', function (res, res, next) {
res.hal({
data: {
firstName: 'Mohandas',
lastName: 'Gandhi',
aliases: [{
firstName: 'Mahatma',
lastName: 'Gandhi'
}, {
firstName: 'Bapu'
}]
}
})
})
app.listen(4000)
Let's test it:
$ curl 'http://localhost:4000'
{"data": {"firstName":"Mohandas","lastName":"Gandhi","aliases":[{"firstName":"Mahatma","lastName":"Gandhi"},{"firstName":"Bapu"}]}}
$ # Let's just get the first name
$ curl 'http://localhost:4000?fields=lastName'
{"data":"lastName":"Gandhi"}}
$ # Now, let's just get the first names directly as well as from aliases
$ curl 'http://localhost:4000?fields=firstName,aliases(firstName)'
{"data":"firstName":"Mohandas","aliases":[{"firstName":"Mahatma"},{"firstName":"Bapu"}]}}
Note: take a look at /example
.
Look at json-mask for the available syntax of the fields
param.
query
specifies the query-string to use. Defaults to fields
app.use(partialResponse({
query: 'filter'
}))
MIT. See LICENSE
FAQs
Express middleware for filtering-out parts of HAL+JSON responses based on the `fields` query-string.
We found that express-partial-hal-response demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.