A simple typescript/javascript wrapper for the Dutch : House of Representatives OData API.
GitHub Repository
NPM Package
Wrapper Documentation
To get started with the api in your project. First install the package by writing
npm install gegevensmagazijn.ts
in your project location
Please consider reading the following documentation before using this package.
To use the api in your project, first import the package by writing
import { ODataRequest } from 'gegevensmagazijn.ts'
Then create a new instance of the class by writing.
- The parameter is the name of the entity you want to query
- Available entities are listed on the API's website
const request = new ODataRequest("Fractie")
If you want to gather information about a specific entity, you can use the findById
method.
request.findById("d720f5af-0516-408a-b830-0b6ffb8a581c")
To properly use the wrapper, you need to know the functions that are available to you. For this you can use the documentation. Examples
Now you can apply the 'functions'
to the request. For example, if you want to get the chairs of a specific fraction, you can use the expand
method
like this:
request.expand("FractieZetel")
It's important to note that
Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.
So if you want to use these options, you cannot use the findById method. Instead, apply the functions to the request directly.
Once you applied all the functions you want to the request, you can pick one of the following options to process the request.
- Use the
build()
method to get the query url. This can be used to make a request with a different library.
request.build() // https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Fractie/d720f5af-0516-408a-b830-0b6ffb8a581c?$expand=FractieZetel
- Use the
request()
method to make a request with cross-fetch
request.request().then((response) => {
console.log(response) // { ... }
})
The wrappers usage would look something like this:
import { ODataRequest } from 'gegevensmagazijn.ts'
const request = new ODataRequest("Fractie")
request
.findById("d720f5af-0516-408a-b830-0b6ffb8a581c")
.expand("FractieZetel")
request.request().then((response) => {
console.log(response) // { ... }
}).catch((error) => {
console.log(error)
})
or
import { ODataRequest } from 'gegevensmagazijn.ts'
const request = new ODataRequest("Fractie")
request
.expand("FractieZetel")
.filter("Afkorting ne 'CU'")
.top(10)
console.log(request.build()) // https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Fractie?$top=10&$expand=FractieZetel&$filter=Afkorting%20ne%20%27CU%27
const request = new ODataRequest('Besluit')
.select('id')
.expand('Zaak', '$select=Onderwerp')
.orderby('Status')
.filter("BesluitSoort eq 'Ingediend'")
.select('BesluitSoort');
console.log(request.build());
Result:
https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Besluit?$orderby=Status asc&$expand=Zaak($select=Onderwerp)&$select=id,BesluitSoort&$filter=BesluitSoort eq 'Ingediend'
const request = new ODataRequest('Fractie')
.expand('FractieZetel', '$select=Id')
.filter('AantalZetels gt 10 and AantalZetels lt 50')
.filter("Afkorting ne 'D66'")
.orderby('AantalZetels', 'desc')
.skip(1)
.count(true)
.format('minimal');
console.log(request.build());
Result:
https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Fractie?$skip=1&$count=true&$orderby=AantalZetels desc&$expand=FractieZetel($select=Id)&$filter=AantalZetels gt 10 and AantalZetels lt 50 and Afkorting ne 'D66'&$format=minima
l
This project is dependent on:
Dutch : House of Representatives OData API
| https://opendata.tweedekamer.nl
cross-fetch - A light-weight module that brings fetch to Node.js
| https://github.com/lquixada/cross-fetch
TypeDoc - Documentation generator for TypeScript projects.
| https://typedoc.org/