Giter VIP home page Giter VIP logo

lunchtalk's Introduction

Building micro-services in Haskell + Servant

This repository contains the source files of two (very) simple wishlist micro-services. Its purpose is to show how easy it is to get started with building micro-services in Haskell (and using the Servant library).

The first service wishlist-simple is a wishlist service storing a single user's personal wishes. The second service wishlist-multitenant extends wishlist-simple to also store the wishlists of multiple users. More information on the two services can be found in the original slides for this talk.

How to run:

First, clone this git repository and cd into its root folder. Next, to run the wishlist-simple service, execute the command cabal run wishlist-simple. Similarly, to run the wishlist-multitenant service, run cabal run wishlist-multitenant. The respective service will then start locally on port 8080, where you can query it according to its API.

How to query:

  • The wishlist-simple service provides the following (informal) API:

    GET  /wishes         -- retrieve all wishes stored so far on the service
    
    GET  /wishes/{shop}  -- retrieve all wishes at the given {shop}, which
                         -- must be one of "amazon", "zalando", or "otto".
    
    POST /wishes         -- add a new wish to the wishlist, which needs to
                         -- be send in the request body as a JSON object as
                         -- follows:
                         --
                         -- {"name": "my favorite wish!", "shop": "Amazon"}
                         --
                         -- where the wishes "shop" attribute must be either
                         -- one of "Amazon", "Zalando", or "Otto".
    

    For example, when the wishlist-simple service is running, we could retrieve the current wishlist of stored wishes using the following HTTP request:

    curl http://localhost:8080/wishes
    

    And to add a new wish, we would send the follwing HTTP request:

    curl \
      -H "Content-Type: application/json" \
      -d '{"name": "Game of Thrones 8", "shop": "Amazon"}' \
      http://localhost:8080/wishes
    
  • The wishlist-multitenant service provides the same API as wishlist-simple, except that a client also needs to provide a Tenant Header in all its request indicating which user's wishlist should be retrieved

    For instance, to add a new wish to the wishlist of user hans, we would send the following HTTP request:

      curl \
      -H "Content-Type: applicatpion/json" \
      -H "Tenant: hans" \
      -d '{"name": "Game of Thrones 8", "shop": "Amazon"}' \
      http://localhost:8080/wishes
    

    And similarly, to retrieve hanss wishlist:

    curl -H "Tenant: hans" http://localhost:8080/wishes
    

Playing around with/modifying the source code:

The main source file for the wishlist-simple service is in src/WishlistSimple.hs, the main source file for wishlist-multitenant is in src/WishlistMT.hs. Most code is shared among the two micro-services in src/Wishlist/Common; code that is specific to each one of the services, is located in src/Wishlist/Simple and src/Wishlist/MultiTenant, respectively.

lunchtalk's People

Watchers

 avatar James Cloos avatar

Forkers

abbi-gaurav

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.