3.1.1 • Published 10 months ago

gegevensmagazijn.ts v3.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Gegevensmagazijn.ts

A simple typescript/javascript wrapper for the Dutch : House of Representatives OData API.

GitHub deployments

NPM NPM GitHub Workflow Status (with event)

GitHub Repository

https://github.com/nowarries/gegevensmagazijn.ts

NPM Package

https://www.npmjs.com/package/gegevensmagazijn.ts

Wrapper Documentation

https://nowarries.github.io/gegevensmagazijn.ts/

Table of Contents

Installation

To get started with the api in your project. First install the package by writing

npm install gegevensmagazijn.ts in your project location

Usage

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. 1. The parameter is the name of the entity you want to query 2. 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")

Functions

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.

Processing the request

Once you applied all the functions you want to the request, you can pick one of the following options to process the request.

  1. 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
  1. Use the request() method to make a request with cross-fetch
request.request().then((response) => {
    console.log(response) // { ... }
})

Summary

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

Advanced examples

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

Dependency

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/

3.0.3

10 months ago

3.1.1

10 months ago

3.0.2

10 months ago

3.1.0

10 months ago

3.0.1

10 months ago

3.0.0

10 months ago

2.1.0-alpha

1 year ago

2.0.0

1 year ago

2.0.0-alpha

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago