Giter Club home page Giter Club logo

draft-ticket-price-service-demo's Introduction

draft-ticket-price-service-demo

A simple Web service example.

Calculates prices for each ticket as well as a total price of a draft ticket. Uses external Web services for getting a base price for destination and applicable tax rates. A demo version of such services can be found at web-api-demo.

Requirements:

  • OpenJDK 8+
  • Spring Boot
  • Gradle

Build

Execute:

On Windows:

.\gradlew build

On UNIX:

./gradlew build

Usage

  1. Start external Web services for getting base prices and applicable taxes. URLs of external services as well as a server port of this application has been defined in application.properties.

  2. cd to the directory of the JAR file and start the Draft Ticket Price Service.

    On Windows:

     cd ${PROJECT_ROOT}\build\libs
     java -jar .\draft-ticket-price-service-x.y.z[-SNAPSHOT].jar

    On UNIX:

     cd ${PROJECT_ROOT}/build/libs
     java -jar draft-ticket-price-service-x.y.z[-SNAPSHOT].jar
  3. Input data are received from a web client by a GET request with http://localhost:9090/draftprice as a URL and a list of JSON objects in the Message Body.

    An example in Python:

      #!/usr/bin/env python3
      
      import sys
      import requests
      import json
      
      
      def main():
          url = 'http://localhost:9090/draftprice'
          data =
          [
              {'passengerType': 'ADULT', 'destination': 'Vilnius', 'itemsOfLuggage': 2},
              {'passengerType': 'CHILD', 'destination': 'Vilnius', 'itemsOfLuggage': 1}
          ]
          headers = {'Content-Type': 'application/json'}
          
          resp = requests.get(url, headers=headers, data=json.dumps(data))
          print(resp.content.decode('utf-8'))
      
      
      if __name__ == '__main__':
          sys.exit(main()) or 0
  4. A response to the Web client is also sent in JSON format.

    An example of a response content received by the Web client:

    {
      "tickets":[
        {
          "ticketType":  "ADULT",
          "count": 1,
          "price": 12.10
        }, {
          "ticketType": "LUGGAGE",
          "count": 2,
          "price": 7.26
        }, {
          "ticketType": "CHILD",
          "count": 1,
          "price": 6.05
        }, {
          "ticketType": "LUGGAGE",
          "count": 1,
          "price": 3.63
        }
      ],
      "totalPrice": 29.04
    }

draft-ticket-price-service-demo's People

Contributors

janissl 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.