January 2018
Intermediate to advanced
336 pages
7h 22m
English
Open your lib/bundle.js and add the following inside the module.exports function, after the bundle-creation API you added previously.
| | /** |
| | * Retrieve a given bundle. |
| | * curl http://<host>:<port>/api/bundle/<id> |
| | */ |
| | app.get('/api/bundle/:id', async (req, res) => { |
| | const options = { |
| | url: `${url}/${req.params.id}`, |
| | json: true, |
| | }; |
| | try { |
| | const esResBody = await rp(options); |
| | res.status(200).json(esResBody); |
| | } catch (esResErr) { |
| | res.status(esResErr.statusCode || 502).json(esResErr.error); |
| | } |
| | }); |
This code block sets up a handler for the /bundle/:id route, which will allow us to retrieve a book bundle by its ID. Note ...
Read now
Unlock full access