Activity 35: Documentation of your Basic CRUD API
Walter John Salibay
2 min read
STEP 1: Set Up python Flask in cmd
First is I’ve set up the python flask virtual and make sure that it is activated and connected it on GitHub repository which named as basic-crud-flask
STEP 2: Follow the basic crud blueprint structure
# TODO: import flask LIBRARY
from flask import Flask, jsonify, request
# call the flask object
app = Flask(__name__)
# create list of dictionaries
students = [{}]
# get method
@app.route('/students', methods=['GET'])
def get_students():
# get method : Get a specific student by ID
@app.route('/students/<int:student_id>', methods=['GET'])
def get_student(student_id):
# put method
@app.route('/students/<int:student_id>', methods=['PUT'])
def update_student(student_id):
# delete method
@app.route('/students/<int:student_id>', methods=['DELETE'])
def delete_student(student_id):
# Dont forget this
if __name__ == '__main__':
app.run(debug=True)
STEP 3: Open Pycharm and set up the templates, index.html
, and app.py
I’ve imported the flask code
created a list of dictionaries of students
then copy and paste all the methods such us “GET“, “POST“, “PUT”, and “DELETE“
STEP 4: Run “app.py
“ on terminal then copy the url into Postman
copy the url: http://127.0.0.1:5000 then paste it on Postman
on the url: to use GET method, /students should be added on the url like “http://127.0.0.1:5000/students“ to get the data of all students
STEP 5: Then explore the created data in Postman using the methods “GET“, “POST“, “PUT“, and “DELETE“
that’s all, thank you.
0
Subscribe to my newsletter
Read articles from Walter John Salibay directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by