# gegevensmagazijn.ts

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

Latest version **3.1.1** (published 2023-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install gegevensmagazijn.ts
pnpm add gegevensmagazijn.ts
yarn add gegevensmagazijn.ts
bun add gegevensmagazijn.ts
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2023-07-28 |
| First published | 2022-11-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 35.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Coen Warries |
| Maintainers | nowarries |

## Links

- npm: https://www.npmjs.com/package/gegevensmagazijn.ts
- npm.io page: https://npm.io/package/gegevensmagazijn.ts

## Dependencies (1)

- [cross-fetch](https://npm.io/package/cross-fetch.md) ^3.1.5

## Recent versions

- 3.1.1 (latest) — 2023-07-28
- 3.1.0 — 2023-07-03
- 3.0.3 — 2023-07-03
- 3.0.2 — 2023-07-03
- 3.0.1 — 2023-07-03
- 2.1.0-alpha — 2022-12-01
- 2.0.0 — 2022-11-30
- 2.0.0-alpha — 2022-11-30
- 1.2.1 — 2022-11-30
- 1.2.0 — 2022-11-30

## README

# Gegevensmagazijn.ts

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

![GitHub deployments](https://img.shields.io/github/deployments/nowarries/gegevensmagazijn.ts/github-pages?style=for-the-badge&label=Wrapper%20Documentation&link=https%3A%2F%2Fnowarries.github.io%2Fgegevensmagazijn.ts%2F)

![NPM](https://img.shields.io/npm/dt/gegevensmagazijn.ts?style=for-the-badge)
![NPM](https://img.shields.io/npm/l/gegevensmagazijn.ts?style=for-the-badge)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/nowarries/gegevensmagazijn.ts/jest.yml?style=for-the-badge&label=%F0%9F%83%8F%20Tests)

**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](#installation)
- [Usage](#usage)
  - [Functions](#functions)
  - [Processing the request](#processing-the-request)
  - [Summary](#summary)
- [Advanced examples](#advanced-examples)
- [Dependencies](#dependency)

## 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.
>- [API's documentation](https://opendata.tweedekamer.nl/documentatie/odata-api)
> - [Wrapper documenation](https://nowarries.github.io/gegevensmagazijn.ts/)
> - [OData documentation](https://www.odata.org/getting-started/basic-tutorial/)

To use the api in your project, first import the package by writing

```typescript
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](https://opendata.tweedekamer.nl/documentatie/informatiemodel)

```typescript
const request = new ODataRequest("Fractie")
```

If you want to gather information about a specific entity, you can use the `findById` method.

```typescript
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](https://nowarries.github.io/gegevensmagazijn.ts/).
Examples 

Now you can apply the ['functions'](https://opendata.tweedekamer.nl/documentatie/odata-api#heading-116)
to the request. For example, if you want to get the chairs of a specific fraction, you can use the `expand` method
like this:
```typescript
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.

```typescript
request.build() // https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Fractie/d720f5af-0516-408a-b830-0b6ffb8a581c?$expand=FractieZetel
```

2. Use the `request()` method to make a request with [cross-fetch](https://www.npmjs.com/package/cross-fetch)

```typescript
request.request().then((response) => {
    console.log(response) // { ... }
})
```

### Summary

The wrappers usage would look something like this:

```typescript
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 

```typescript
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

```typescript
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'
```

```typescript
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
> <br> | https://opendata.tweedekamer.nl

> cross-fetch - A light-weight module that brings fetch to Node.js
> <br> | https://github.com/lquixada/cross-fetch

> TypeDoc - Documentation generator for TypeScript projects.
> <br> | https://typedoc.org/

---
_Source: https://npm.io/package/gegevensmagazijn.ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
