π Create a file named app.py with the following code and run it on terminal.
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Student(Resource):
def get(self, name):
return {'student': name}
api.add_resource(Student, '/student/<string:name>')
app.run(port=5000)
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Student(Resource):
def get(self, name):
return {'student': name}
api.add_resource(Student, '/student/<string:name>')
app.run(port=5000)
This application imports Flask, Resource, and API. Then creates an app and api objects. Then creates a class. Then calls a function using api object to enable GET request. Then it calls run function using app object to host it on port=5000
Comments
Post a Comment