Giter Site home page Giter Site logo

epf-api-tp2's Introduction

EPF-API-TP

  • Question 1: Which Python library/framework is often used to create fast, simple REST APIs?

    • FastAPI
  • Question 2: What's the main difference between Django, Flask and FastAPI in terms of performance and speed?

    • FastAPI is renowned for its increased speed and performance compared with Django and Flask.
  • Question 3: What is an endpoint in the context of REST APIs?*

    • A specific URL to which a request can be sent to interact with the API.
  • Question 4: What are the main HTTP verbs used to define REST API methods?

    • GET, POST, PUT, PATCH, DELETE
  • Question 5: In the context of REST APIs, what does the term "middleware" mean?

    • Intermediate software that processes the request before it reaches the main application.
  • Question 6: Which Python library is often used to serialize and deserialize JSON data in the context of REST APIs?

    • json.dumps() and json.loads()
  • Question 7: What is the main use of the HTTP "PUT" method in the context of REST APIs?

    • Update an existing resource, or create one if it doesn't exist.
  • Question 8: In FastAPI, how do you define an endpoint to handle a POST request with JSON data?*

    • @app.post("/endpoint")

Creating an API with FastAPI

Introduction

In this exercise you are going to encapsulate data processing and machine learning model execution logic to make predictions on a well-known dataset: iris kaggle dataset

Few elements to remember about the REST Protocol

REST (Representational State Transfer) is an architectural style for designing networked applications. RESTful APIs (Application Programming Interfaces) conform to the principles of REST, allowing systems to communicate over HTTP in a stateless manner; Some important aspects are:

  • Resources: Everything is a resource, identified by a unique URI.

  • HTTP Methods: CRUD operations are performed using standard HTTP methods (GET, POST, PUT, DELETE).

  • Stateless: Each request from a client contains all the information needed to understand and fulfill the request.

Key Concepts in FastAPI:

  • Endpoint:

  • Basic HTTP Methods:

  • Request and Response:

Evaluation requirements

The evaluation criteria will be as follows:

  • Proper functioning of endpoints
  • Clear documentation of code, use of explicit names and compliance with REST naming conventions. Please follow pep-8 convention for documenting your functions (exemple at the end of the README)
  • Static swagger generation through an API route
  • Completion of unit tests

Objective

Before starting the exercise, download the contents of the main branch of the following git repo and create your own private repo: https://github.com/klemmm922/EPF-API-TP/
Don't forget to add me to the repo with the following email address: [email protected]

About the API workflow:

  • The router.py file contains references to the routers defined in the routers folder.

  • The routers file contains the declaration of all API routes by tags

  • The Services folder must contain the functions that are called in the route declaration

  • Step 1: Installing libraries: Install the libraries in the requirements.txt

  • Step 2: First launch: Execute the main.py file in the root folder and access it.

  • Step 3: Redirect root API: Redirect the root endpoint of your API to the automatic swagger documentation

  • Step 4: Access the swagger documentation: Access to the swagger built automatically by FastAPI

  • Step 5: First call to the API: Make an API request on the hello route using the swagger directly or a tool like insomnia or postman

  • Step 6: Access the dataset: Create a route in api/routes/data to download and save the contents of the following kaggle dataset in the src/data folder: https://www.kaggle.com/datasets/uciml/iris. If you're having too many problems, simply download the dataset from the kaggle website. documentation : https://www.geeksforgeeks.org/how-to-download-kaggle-datasets-into-jupyter-notebook/

  • Step 7: Loading the Iris Flower dataset: Add an endpoint to load the iris dataset file as a dataframe and return it as a json.

  • Step 8: Processing the dataset: Add an endpoint to be able to perform the necessary processing on the data before being able to train a model with it.

  • Step 9: Split in train and test: Add an endpoint to split the iris dataset as train and test and send back a json with both

  • Step 10: Parameters init: Go to scikit learn and select any classification model to be used on the iris dataset (performance is of no interest to us in this course). Look at the parameters you need to use for this model and store them in the file src/config/model_parameters.json

  • Step 11: Training the classification model: Add an endpoint to train a classification model with the processed dataset as input and saved this model in the folder src/models.

  • Step 12: Prediction with Trained Model: Add endpoint to make predictions with trained model and parameters. This endpoint have to send back the predictions as json.

  • Step 13: Create the Firestore collection: Create the firestore collection "parameters" with the following parameters: "n_estimators", "criterion". The name of the document with the parameters have to be : parameters.

  • Step 14: Retrieve parameters from Firestore: Add an endpoint to retrieve parameters from Firestore.

  • Step 15: Update and add Firestore parameters: Add endpoints to update or add parameters in Firestore.

  • Step 16: Authentication: Implement authentication through Firestore authentication

  • Step 17: User management: Extend authentication to include user registration, login and logout endpoints. Explore also user roles and permissions. Allow only admin users to access to the list of user

  • Step 18: Protection against Denial of Service (DoS) attacks: Implement rate limiting by user

  • Step 19: API versioning: Add the information about the version of your API. (you are on version 1.0) Also add the prefix to your routes to indicate the version.

  • Step 20: Error Handling: Add a custom error responses for error 404 and provide meaningful error message.

  • Step 21: API testing: Implement unit tests for your functions and enpoints

  • Step 22: CI/CD pipeline: Define a CI/CD pipeline on github using github Actions to launch your tests after every push

The completion of this TP is relatively long and may overtake TP3

Documentation link :

Pep-8 docstring example :

""" Retrieve content of a json file

Args: path (str): The path of the file

Returns: JSON object: The json object with the parameters """

epf-api-tp2's People

Contributors

cyjerox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.