SA53_bhuvesh_kumar_fibonacci http://168.138.176.208/
- Dropwizard Web service.
- React UI.
- Python Flask Rest web service.
- Python Flask Docker Instrcutions
- Access Deployed REST web service
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
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]
}
- 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>
</
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
Configuration
cors.setInitParameter("allowedOrigins", "*");
cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin");
cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");
Python and Flask REST web service http://168.138.176.208/
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
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]
}
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
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
$ git clone https://github.com/bhuveshsharma09/my-flask-app.git
$ cd my-flask-app
$ python3 -m pip install -r requirements.txt
python3 app.py
Current configuration for host is '0.0.0.0' and port is 80
Link: http://168.138.176.208/
-
Step 1: Go to http://168.138.176.208/ and enter a number in input field and hit 'compute' button
-
Step 2: The web app will send request to http://168.138.176.208/fibonacci/
- Step 3: The web app will show the reponse in the page
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.
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
- Formik
npm install formik --save
- Loading the webpage in web browser
- submitting value and receieving the response