Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@rdfjs/fetch-lite
Advanced tools
Wrapper for fetch to simplify sending and retrieving RDF data.
This is a light version of the @rdfjs/fetch
package, without the @rdfjs/formats-common
dependency.
It is useful when you want to make a build for the browser with a reduced set of parsers and serializers.
The formats
options is required for this package.
See also the @rdfjs/fetch
documentation.
Since version 3.0, this packages is ESM only. Check version 2.x if you are looking for a CommonJS package.
The package exports a fetch
function which wraps the request and response object for on-the-fly RDF quad processing.
The function accepts the same parameters as fetch and some additional options. It also provides extra methods.
The options
object accepts the following additional parameters:
formats
: A formats-common-compatible object which contains a set of parsers and serializers.
This parameter is required.factory
: If given, the factory will be used to create a Dataset when dataset()
is called.
If the parameter is not given, the dataset()
method will not be attached to the response.fetch
: An alternative fetch implementation.
By default nodeify-fetch will be used.The following options
influence the logic of RDF quad processing:
headers.accept
: The accept header field will be automatically set base on the list of available parsers from the formats
object.
If it's already set it will not be overwritten.
This can be useful when only a subset of the available parsers should be used.headers.content-type
: When the request has a body, this header field will be automatically set to use matching media type for the corresponding serializer.
By setting this field manually a specific serializer can be enforced.body
: If the request should send quads, the quads must be given either as a stream or as an iterable.
Iterables will be converted to streams before they are handed over to the serializer.The following methods are attached to the standard fetch response object:
quadStream()
: This method returns the quads of the response as stream.
The parser is selected based on the content type header field.dataset()
: This method uses the quadStream()
method to parse the content and will pipe it into a dataset, which is also the return value.
This method is only available when the factory
option is given.The Content-Type
header of the response can be changed or set before calling quadStream()
or dataset()
.
That allows enforcing a specific parser or can be used to fix a lacking header.
This example fetches data from a resource on Wikidata.
The stream API is used to process all quads.
For all rdfs:label
quads of the defined entity, the object language and value will be written to the console.
const formats = require('@rdfjs/formats-common')
const fetch = require('@rdfjs/fetch-lite')
const entity = 'http://www.wikidata.org/entity/Q2'
const label = 'http://www.w3.org/2000/01/rdf-schema#label'
fetch('https://www.wikidata.org/wiki/Special:EntityData/Q2.ttl', { formats })
.then(res => res.quadStream())
.then(quadStream => {
return new Promise(resolve => {
quadStream.on('end', resolve)
quadStream.on('data', quad => {
if (quad.subject.value === entity && quad.predicate.value === label) {
console.log(`${quad.object.language}: ${quad.object.value}`)
}
})
})
})
.catch(err => console.error(err))
FAQs
Wrapper for fetch to simplify sending and receiving RDF data
The npm package @rdfjs/fetch-lite receives a total of 12,226 weekly downloads. As such, @rdfjs/fetch-lite popularity was classified as popular.
We found that @rdfjs/fetch-lite demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.