Building the /block/:blockHash endpoint

Let's use the getBlock method inside of /block/:blockHash endpoint to retrieve a specific block by its blockHashLet's follow these next steps to build the endpoint: 

  1. The first thing that we want to do in this endpoint is to use the blockHash value that is sent with the /block/:blockHash request. We can access this blockHash on the req.params object. Go to the dev/networkNode.js file and in the /block/:blockHash endpoint that we defined previously, add the following highlighted code: 
app.get('/block/:blockHash', function(req, res) {         const blockHash = req.params.blockHash;});

Essentially, when we hit the /block/:blockHash endpoint, we're accessing the hash value of a block present on a particular ...

Get Learn Blockchain Programming with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.