-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (20 loc) · 727 Bytes
/
index.js
File metadata and controls
24 lines (20 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const harryPotterAPI = require('./service/http')
const { parseQueryStringToString } = require('./helpers/queryStringParser')
var express = require('express')
var app = express()
app.get('/v1/characters', async function(req, res) {
try {
const parsedParams = parseQueryStringToString(req.query)
const response = await harryPotterAPI.getCharacterByQuery(parsedParams)
res.status(response.status).json(response.data)
} catch (e) {
const status = e.response.status || 500
return res.status(status).send()
}
})
app.get('/', function(req, res) {
res.send('hello world')
})
app.listen(port = '3000', () => {
console.log(`Example app listening at http://localhost:${port}`)
})