Skip to content

Developers Notes

Overview

This document is the first place that developers should visit to go through various concepts has been implements in this project and boost the headstart for development.

Develop Progress

[4] API HTTPs methods

Method Description
GET The GET method requests a representation of the specified resource. Requests using GET should only retrieve data
HEAD The HEAD method asks for a response identical to a GET request, but without the response body
POST The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server
PUT The PUT method replaces all current representations of the target resource with the request payload
DELETE The DELETE method deletes the specified resource
CONNECT The CONNECT method establishes a tunnel to the server identified by the target resource
OPTIONS The OPTIONS method describes the communication options for the target resource
TRACE The TRACE method performs a message loop-back test along the path to the target resource
PATCH The PATCH method applies partial modifications to a resource

Status Codes

Q: How do you know when to yield status code, and which codes should be returned?

A: The status code when you finish a task from requests from users, or when hit any errors.

The status code must be meaningful, because its used by another systems.

The status codes from MDN documents are useful:

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:

[+] Informational responses (100 – 199)

[+] Successful responses (200 – 299)

[+] Redirection messages (300 – 399)

[+] Client error responses (400 – 499)

[+] Server error responses (500 – 599)

For more detail: HTTP response status codes

The FastAPI has supported this too, read through Response Status Code

Design an API

This design go to basic protocol to create an API endpoint from the scrath

Following topics are required to build, develop this project

[1] API: Introduction, Why, How

[2] What information are required to gather before you develop? With and without Business Analyst?

[3] API Concentps from VEEAM: VEEAM REST Methods

[5] HTTPs methods progress

a) For GET

  • Arguments Parsing

  • Validate Elements

  • Construct DML Query

  • Returned response

b) For POST | PUT

  • Arguments Parsing

  • Validate Elements

[1] Check coi có exists True/False Routes [2] Fetching data {current} Routes [3] User update requirement {mapping-change} Routes [4] Update components CRUD

  • Construct DML Query

  • Returned response

c) For DELETE

  • Arguments Parsing

  • Validate Elements

  • Construct DML Query

  • Returned response

[5] Design Response Output:

a) For GET

List of Base Metadata

b) For POST | PUT

Returned body of item

c) For DELETE

For Testing

Test always is a part of developer when create featute follow to TDD progress.

FastAPI intergrate testing with pytest, httpx and some fake data generate tools like Faker

ref: FastAPI Testing

ref: Faker to create fake data

ref: Factoy Boy

Troubleshooting

[1] Align database models to CRUD operations arguments

[2] The output results

Some errors that developers usually create:

[1] Unboundlocalerror

Read: https://linuxhint.com/python-unboundlocalerror/

[2] Missing the packages that required in requirements.txt

[3] Should import <module> or from <module> import x,y,z

It's depends, but when import, Python will know to cached the moduled has loaded.

It's based on timimg for import, which lead to initation time (import time) is larger.

It's based on the way of reminders, occurs when we not familars with the module.

[4] Naming for functions, objects, modules

Should read: .NET Framework naming guidances

a) For objects: use upper case with _. E.g: REQUIRED_COLUMNS instead of RequiredColumns

b) For class: use Camel syntax. E.g: ResponseAdjustment

c) For function: use snake syntax. E.g: def get_element

Its should align with prefix for module.

[5] Missing type hint and documents for usages.