Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD - Api initializing #23

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# Boegle
Amsterdam OBA | To search a book

## Table of contents

[Getting started](##getting_started)

## Getting started

Install all dependencies
```
npm install
```

Start application
```
npm start
```

Standard port is 3000
```
localhost:3000
```


21 changes: 21 additions & 0 deletions controls/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fetch = require('node-fetch')
const env = require('dotenv')
const parseString = require('xml2js').parseString

env.config()

const publicKey = process.env.PUBLIC_KEY
const path = 'search'
const baseUrl = 'https://zoeken.oba.nl/api/v1/' + path + '/'
const search = 'q=boek'

function getData() {
return fetch(baseUrl + '/?authorization=' + publicKey + '&' + search)
.then((response) => response.text())
.then((xml) => parseString(xml, (err, data) => console.log(data.aquabrowser)))
.catch((error) => console.log(error))
}

module.exports = {
getData
}
3 changes: 3 additions & 0 deletions controls/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const express = require('express')
const router = express.Router()
const api = require('./api')

api.getData()

router.get('/', (req, res) => {
res.render('index')
Expand Down