Skip to main content

API tools for consistent response formatting and validation

Project description

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:

  1. 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)
  1. 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) -> dict both 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) -> dict Not 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) -> dict By 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

just_simplify_api-1.0.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

just_simplify_api-1.0.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file just_simplify_api-1.0.2.tar.gz.

File metadata

  • Download URL: just_simplify_api-1.0.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for just_simplify_api-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8b803659fda89320c5de62ce3265dd3ddd16714fe1457a037fc8fca72aad5e89
MD5 09309cbd4d427d26e70fdd4fddef9f6d
BLAKE2b-256 894a1f2fc95100915ff4f1e1b34208bed52c58e497c4d9ad46e5e2eeaa995a7f

See more details on using hashes here.

File details

Details for the file just_simplify_api-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for just_simplify_api-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79b6fb0f6807b29417ec26b9a38f835790809ab63675ba7ea48f9d4eb08569ea
MD5 8f81685c8059b41e65346a73573e5498
BLAKE2b-256 ea255dd951a9ce7bb7fd177914fd7cf22f4f3cb37e2e66b3bcec9cd629cc9dfb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page