GithubHelp home page GithubHelp logo

microservice-example's Introduction

Microservice example

A nats, asyncio, aiohttp, sqlalchemy example for creating a microservice.

Installation

git clone https://github.com/ldej/microservice-example
cd ./microservice-example
docker-compose build

Basic usage

Start the project

docker-compose up

Make a call to create a thing:

curl -X POST 'http://127.0.0.1:5000/thing_service.create_thing' -d '{"name": "Alice"}'

See that a thing is created:

curl -X POST 'http://127.0.0.1:5000/thing_service.get_things'

Try the basic greeting service:

curl -X POST 'http://127.0.0.1:5000/greeting_service.hello' -d '{"name": "Bob"}'

See the asyncio in action. The greeting_service.hello_sleep call will sleep for 10 seconds. So open two terminals, in the first one:

curl -X POST 'http://127.0.0.1:5000/greeting_service.hello_sleep' -d '{"name": "Sleepy Bob"}'

And in the second:

curl -X POST 'http://127.0.0.1:5000/greeting_service.hello' -d '{"name": "Awake Bob"}'

The second call should return before the first call.

Websockets

Make sure the project is started. Open frontend/index.html. In the subscribe section, the RPC input will be filled with websocket_test.websocket_test. When pressing send, the websocket will be subscribed to that message on nats. There are two ways to confirm that it works. The first is to do:

curl -X POST 'http://127.0.0.1:5000/websocket_test.hello_websocket' -d '{"websockets": "are awesome"}'

This is a normal HTTP POST call. The call websocket_test.hello_websocket will send a message over nats on channel websocket_test.websocket_test. The browser will then show the message that was sent.

The second way to confirm is by using the publish section of the frontend. This will send the message to the backend over the websocket (instead of HTTP POST). And it should give the same result in the frontend.

microservice-example's People

Watchers

 avatar  avatar

Forkers

webclinic017

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.