Activity 35: Documentation of your Basic CRUD API

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

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

Walter John Salibay
Walter John Salibay