https://github.com/hypermedia-app/express-rdf-request
Express middleware for easily accessing RDF payload resource
https://github.com/hypermedia-app/express-rdf-request
Last synced: 17 days ago
JSON representation
Express middleware for easily accessing RDF payload resource
- Host: GitHub
- URL: https://github.com/hypermedia-app/express-rdf-request
- Owner: hypermedia-app
- License: mit
- Created: 2021-04-04T15:48:20.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-14T10:14:47.000Z (almost 3 years ago)
- Last Synced: 2025-09-15T23:37:15.625Z (10 months ago)
- Language: TypeScript
- Size: 239 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# express-rdf-request
Middleware which attaches a `req.resource()` to simplify getting a Graph Pointer to the request payload and `res.resource()` for the easiest possible way to send a Graph Pointer in response.
## Usage
```js
import { resource } from 'express-rdf-request'
import express from 'express'
const app = express()
app.use(resource())
app.use(async function echo(req, res) {
// get resource parsed from body
const resource = await req.resource()
// send it back
res.resource(resource)
})
```
Alternatively, the function can be attached inside a handler to ensure that they are available.
```js
import { attach } from 'express-rdf-request'
app.use(async function echo(req, res) {
await attach(req, res)
// get resource parsed from body
const resource = await req.resource()
// send it back
res.resource(resource)
})
```
## What it does
Uses [@rdfjs/express-handler](https://npm.im/@rdfjs/express-handler) to parse the incoming request as RDF and to serialize responses.
If not otherwise configured, it will attempt parsing the request by setting the requested URL as base IRI. Then, any relative Named Nodes will be made absolute relative to the request URL.
Finally, the node exactly matching the requested URI will be returned as Graph Pointer.
## Configuration
All configuration is optional and also can be used with `attach`.
```typescript
app.use(resource({
factory, // RDF/JS factory - by default uses rdf-ext
getTerm(req: express.Request): NamedNode {
// change the request term
// by default uses the package absolute-url
return req.hydra.term
}
}))
```