GithubHelp home page GithubHelp logo

isabella232 / openapi-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from corda/openapi-sample

0.0 0.0 0.0 48.53 MB

This sample is a develoepr preview of setting up a webapp using Braid server and OpenAPI generator.

License: MIT License

JavaScript 98.42% HTML 0.54% CSS 0.87% Shell 0.17%

openapi-sample's Introduction

openapi-sample

Corda

Introduction

This sample is a developer preview of setting up a React front-end using Braid server and OpenAPI generator. Project Braid is a web server which can automatically detect Corda flows and generate api template in json format. Then, we can use OpenAPI generator to transalate into API libraries in more than 40+ different languages, including javascript, GO, Ruby, and etc. Read this blog to have an overview of Braid: https://medium.com/corda/a-road-to-less-coding-auto-generate-apilibrary-bcbe2def7b30

More information about Braid and OpenApi generator can be found at:

Braid: https://gitlab.com/bluebank/braid

OpenApi-generator: https://github.com/OpenAPITools/openapi-generator

Tools you need

โš ๏ธ You need follow the order of the instructions: Start Corda node -> braid server -> React WebApp

Step1: Downloads and setting up bootstrap Corda network

Download openapi-generator.

Find more details at: https://github.com/OpenAPITools/openapi-generator

npm install @openapitools/openapi-generator-cli -g

Download and Start the Cordapp.

For this Demo, we are using a modified version of my bootcamp Cordapp. Links:https://github.com/corda/bootcamp-openapi Commands to build & start your nodes:

git clone https://github.com/corda/bootcamp-openapi.git
cd bootcamp-openapi
./gradlew deployNodes
./build/nodes/runnodes

If you need more information on running the Cordapp, please visit our docs at: https://docs.corda.net/tutorial-cordapp.html

Right now, you should have 4 nodes running in your terminal including PartyA, PartyB, PartyC and Notary. Go to the PartyA's node crash shell, you will see the the RPC connection address:

Advertised P2P messaging addresses      : localhost:10003
RPC connection address                  : localhost:10004
RPC admin connection address            : localhost:10005

Srep 2: Start Braid StandAlone Server

At the same directory run:

./gradlew startBraidPartyA

You should have Braid Server running on http://localhost:9004/. And you should see the following in you IntelliJ's console:

io.bluebank.braid.corda.rest.RestMounter - swagger json bound to http://localhost:9004/swagger.json
INFO  io.bluebank.braid.corda.rest.RestMounter - Swagger UI bound to http://localhost:9004/
INFO  io.bluebank.braid.corda.server.BraidCordaStandaloneServer - registering: /cordapps/bootcamp-cordapp/flows/bootcamp.TokenIssueFlowInitiator
INFO  io.bluebank.braid.corda.rest.RestMounter - REST end point bound to http://localhost:9004/api/rest
INFO  io.bluebank.braid.corda.BraidVerticle - BraidVerticle.setupRouter complete -- 2775 msec
io.bluebank.braid.corda.BraidVerticle - BraidVerticle.setupWebserver complete -- 5177 msec
INFO  io.bluebank.braid.corda.BraidVerticle - Braid server started on
INFO  io.bluebank.braid.corda.BraidVerticle - Braid service mounted on http://localhost:9004/api/
INFO  io.bluebank.braid.corda.BraidServer - Braid server started successfully on 9004

Step 3: To continue the example, you have two options.

  • Option 1: Use pre-generated API Libary, and run the react front-end.
  • Option 2: Use openapi generator to generate an API library yourself.

Opt1: Use pre-generated API Libary, and run the react front-end.

Download the React front-end at https://github.com/corda/openapi-sample.git

git clone https://github.com/corda/openapi-sample.git
cd openapi-sample
npm install

At the src/code-gen/io.generated.api folder, it sits the pre-generated APIs. Now, start the react webapp by running:

npm start

The app should be running localhost:3000. And now, you have your corda nodes talking to the React frontend using auto-generated API library!

Opt2: Generate JS API Library using openapi-generator yourself

Generate your own version of API library, by running in terminal:

openapi-generator generate -i http://localhost:10200/swagger.json -g javascript -o ./code-gen --api-package io.generated.api --model-package io.generated.model
  • -i :The json file that is generated by Braid. (You can find address from IntelliJ's terminal)

  • -g which languages do you want your API to be in, (Openapi support more than 30+ server languages)

  • -o :where you are saving the API library

  • --api-package io.generated.api --model-package io.generated.model: Renaming the package for better sighting.

Now, drop this API library into your desired front-end framework, and now you can call the functions just as a normal API Library call!

Quick fix with the current braid build: If you are doing the code-gen yourself, you need to change:

  • Line#62 in NetworkApi.js needs to be change from 'x500-name': opts['x500Name'] to 'x500-name': opts['x500-name'] or change it at the tableList.js.
  • Comment out all the APIs related to VaultQuery in /code-gen/src/index.js including both the import and export

openapi-sample's People

Contributors

peterli-r3 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.