Git Product home page Git Product logo

sa53_bhuvesh_kumar_fibonacci's Introduction

SA53_bhuvesh_kumar_fibonacci http://168.138.176.208/

  1. Dropwizard Web service.
  2. React UI.
  3. Python Flask Rest web service.
  4. Python Flask Docker Instrcutions
  5. Access Deployed REST web service

REST web service using Dropwizard along with UI interface in React

image

  1. Functionality
  2. Example
  3. Dependencies
  4. Port configuration
  5. Testing

Functionality

The web service takes in a numerical value between 1 to 100, and returns the Fibonacci sequence, as well as a sequence that is sorted using the following conditions:

  • Even numbers first, in descending order
  • Odd numbers, in descending order

Example:

If user does a http get to http://myserver:8000/fibonacci with the following json payload:

{
 "elements": 10
} 

it will return me the following JSON:

{
 "fibonacci": [0,1,1,2,3,5,8,13,21,34],
 "sorted": [34,8,2,0,21,13,5,3,1,1]
}

Dependencies

  • Maven dropwizard-core
  • Maven Jersey-moxy
    <dependencies>
        <!-- https://mvnrepository.com/artifact/io.dropwizard/dropwizard-core -->
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-core</artifactId>
            <version>2.0.25</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-moxy -->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>2.34</version>
        </dependency>
    </dependencies>
</

Port configuration

The application port is set at 9090 and admin port is at 9091

String applicationPort = "9090";
String adminPort = "9091";

Please change the port numbers in ~/Program file if needed

CORS headers has been handled

Configuration

cors.setInitParameter("allowedOrigins", "*");
cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin");
cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");

Testing

Using Postman

image

API side message: image

Using React Web app

image

API side message: image

Python and Flask REST web service http://168.138.176.208/

image

  1. Functionality
  2. Example
  3. Dependencies
  4. Port configuration
  5. Testing
  6. Docker build

Functionality

The web service takes in a numerical value between 1 to 100, and returns the Fibonacci sequence, as well as a sequence that is sorted using the following conditions:

  • Even numbers first, in descending order
  • Odd numbers, in descending order

Example:

If user does a http get to http://myserver:8000/fibonacci with the following json payload:

{
 "elements": 10
} 

it will return me the following JSON:

{
 "fibonacci": [0,1,1,2,3,5,8,13,21,34],
 "sorted": [34,8,2,0,21,13,5,3,1,1]
}

Deployed on OCI (Oracle Cloud Infrastructure)

The web service has been deployed on OCI and can we accessed using

Link of the global API (hosted on OCI): http://168.138.176.208/ ;

Link to call API in your program: http://168.138.176.208/fibonacci

Build and Run Docker image using Dockerfile

the docker file helps to build an image of program which can later be run in a container. To do so, please follow the commands

$ git clone https://github.com/bhuveshsharma09/my-flask-app.git

### build docker image

$ docker image build -t my-flask-app .

### check if the image has been build successfully

$ docker image ls

### run the image in a container

$ docker run -d -p 80:80 my-flask-app

How to use

clone the repo

$ git clone https://github.com/bhuveshsharma09/my-flask-app.git

change the working directory to my-flask-app

$ cd my-flask-app

install the requirements

$ python3 -m pip install -r requirements.txt

run

python3 app.py

Configuration

Current configuration for host is '0.0.0.0' and port is 80

Functional prototype deployed at OCI

Link: http://168.138.176.208/

Testing

image

  • Step 3: The web app will show the reponse in the page

Note

The API request url is http://168.138.176.208/fibonacci/ . Only for the demo purpose I developed the page where user can easily enter value and computer fib sequence (using API). Although the API and webpage resides in the same program, the function calls API link to fullfil the requirment.



React web app to call API to computer fibonacci sequence

image

  1. Dependencies
  2. Testing

Simple react web app which takes number value from user and calls an API to compute the fibonacci sequence.

Link of the dropwizard API: https://github.com/bhuveshsharma09/my-dropwiz-app

Link of the global API (hosted on OCI): http://168.138.176.208/ ; http://168.138.176.208/fibonacci

image

Dependencies

  • Formik
 npm install formik --save

Testing

  • Loading the webpage in web browser

image

  • submitting value and receieving the response

image

sa53_bhuvesh_kumar_fibonacci's People

Contributors

bhuveshsharma09 avatar

Stargazers

 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.