January 2019
Beginner to intermediate
776 pages
19h 58m
English
We can use the Flask library to create simple RESTful web services and web applications without having to install any complex web service engines or web application containers.
Listing 7.7 gives the code for a simple web service that gets a number as an input to the RESTful service, and outputs the Fibonacci number and Square of the number:
#!/usr/bin/env python
# Python Network Programming Cookbook, Second Edition -- Chapter - 7
# This program is optimized for Python 2.7.12 and Python 3.5.2.
# It may run on any other version with/without modifications.
from flask import Flask
app = Flask(__name__)
@app.route('/<int:num>')
def index(num=1):
return "Your Python Web Service <hr>Fibonacci("+ str(num) + "): "+ str(fibonacci(num))+ ...Read now
Unlock full access