Just Simplify API
Clean up your API function of tedious response and verification code. Make it easier to see what your API is doing and ensure consistency with all your responses!
Verrify incomming body values
Verifying every value that comes with the request can be tedious and take up a lot of space in your code. Now you can verify all your incomming values with a single function! Heres how:
- Create a bluprint of what kind of values your looking for. Here is an example of what that might look like:
BODY_BLUEPRINT = {
"email": {"required":True, "type":"email"},
"password": {"required":True, "type":"hash"},
"address": [{
"required": True,
"street1": {"required":True, "type":"string", "min_len":5, "max_len":100},
"street2": {"required":False, "type":"string", "min_len":5, "max_len":20},
"city": {"required":True, "type":"string", "min_len":5, "max_len":20},
"state": {"required":True, "type":"selection", "options":["co", "id", "ut"]},
"zip": {"required":True, "type":"zip code"}
}],
"details": {"required":False, "type":"dictionary"}
}
email, password, and details are all examples of arguments with a single value. address is an example of an argument that can contain a list of values ([{address1 details}, {address2 details}, etc...]).
All listed items in the blueprint must contain the following keys:
- required: Boolean Says if the that particular argument is required or optional.
- type: str
Specifies what type of value you are expecting the argument to be. Here is a list of types you can specify:
- "email"
- "hash"
- "zip code"
- "string" (optional "min_len" and "max_len" parameters can be added to limit the length of the string)
- "number"
- "list"
- "dictionary"
- "selection" (required "options" parameter to provide all the posiblities the value can be)
- Run the verification process with
validator(args= request.json, scheme= BODY_BLUEPRINT). If the validation passes, nothing is returned. If it fails, a 400 failed response dictionary will be generated for you with helpfull details.
Generate response
Its important to know the codes for specific return messages and to maintain a consistant return body so end users know what to look for each time. Here are the functions to do this for you:
- 200 Response (Success)
success_200_response(code: int, result: dict) -> dictboth code and result are optional. code is if you want to overwrite the default 200, and result is a dictionary containing any information you want to provide the end user.
- 500 Response (Server Error)
error_500_internal_server(exception: str) -> dictNot only generates a server error, but prints/logs any internal notes that would be helpfull for understanding what happened. This message would be the exeption parameter.
- 400 Response (Bad Request)
error_400_bad_request(err_type: str, **kwargs) -> dictBy default, this will generate a genaric "Bad Request" response. If an error type is provided, it will generate a response tied to that error. Here is a list of err_types you can give:- "Missing Parameters"
- "Missing Headers"
- "Invalid Values"
- "Invalid Headers"
- "Syntax Error"
- "Missing Credentials"
- "Invalid Credentials"
- "Payment Required"
- "Forbidden"
- "Not Found"
- "Method Not Allowed"
- "Request Timeout"
- "Unsupported Media Type"
- **kwargs are any additional details you would like to provide the end user.
Metadata
Release files for just-simplify-api 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| just_simplify_api-1.0.2.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| just_simplify_api-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.2 kB
Release files / just_simplify_api-1.0.2.tar.gz
| Download URL | just_simplify_api-1.0.2.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b803659fda89320c5de62ce3265dd3ddd16714fe1457a037fc8fca72aad5e89
|
|
BLAKE2b-256 checksum How to use checksums |
894a1f2fc95100915ff4f1e1b34208bed52c58e497c4d9ad46e5e2eeaa995a7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.12
|
Release files / just_simplify_api-1.0.2-py3-none-any.whl
| Download URL | just_simplify_api-1.0.2-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79b6fb0f6807b29417ec26b9a38f835790809ab63675ba7ea48f9d4eb08569ea
|
|
BLAKE2b-256 checksum How to use checksums |
ea255dd951a9ce7bb7fd177914fd7cf22f4f3cb37e2e66b3bcec9cd629cc9dfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.12
|