Giter Club home page Giter Club logo

restful-private-blockchain's Introduction

RESTful WEB API with Express.js framework for private Blockchain service

In this project, I built a RESTful API using Express.js that interface with my private blockchain. This project is consist of two end points for use this api.

  • GET Block
  • POST Block

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

To install the software, you need to doownload the following:

  1. Install Node.js on your computer.
  2. Clone or download the repository to your local computer.
  3. Open the terminal and install the packages: npm install.
  4. Initialize node.js project where files are located.
npm init

Installing

This project has the following dependencies:

  "dependencies": {
    "body-parser": "^1.19.0",
    "crypto-js": "^3.1.9-1",
    "express": "^4.16.4",
    "level": "^5.0.1"
  }

You can install and save dependencies:

npm install crypto-js --save
npm install level --save
npm install body-parser --save
npm install express --save

Running the application

Run your application node app.js.

node app.js
  • The REST API provides us two endpoints to interact with our private Blockchain The API is runs on localhost, with port 8000.

Test the application

GET Block

  • URL : /block/{BLOCK_HEIGHT}

  • Method : GET

  • URL Path Params : BLOCK_HEIGHT (Retrive Block Height)

curl --request GET -i http://localhost:8000/block/0  # will return Block #0 from blockchain

POST Block

  • URL : /block
  • Method : GET
  • Request Body : {"data" : "some data example"}
curl -X POST \
  http://localhost:8000/block \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: 1e551722-4382-49cc-84f1-19d3d433c1e7' \
  -d '{
    "data":"Some data example"
}'

Built With

  • Node.js - The JavaScript runtime used
  • Express.js - The web API framework used
  • LevelDB - Used to persist blockchain data on disk

Authors

restful-private-blockchain's People

Contributors

minqukanq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.