Giter VIP home page Giter VIP logo

python-module-connector's Introduction

python-module-connector

object used to connect different backend and frontend components. with the aim of being able to better control the different scenarios that could occur with the communication of these.

structure

Attribute Type Default Description
success boolean False tells us if the process that the component is in charge of is completed successfully or not
message string module_connector a message is left here depending on the conclusion of the component. for example: created_user, existing_name, id_no_found
response list / dict [] All the content that should come from the component is sent here, it can be a list, an element as such, but never a string, boolean or integer value, for reasons of scalability
code integer 500 HTTP code

Simple example

although the component is called a module connector. The most recommended is to define a variable with the name of output when creating a new connector, since it is more readable. it is also recommended to define it as let so that it never deceives us with other classes, functions or services

# include library
from module_connector import Moduleconnector

# create default output from module connector
output = Moduleconnector()

# your code
arrClientList = [
    { "id":1, "name": "diana" },
    { "id":2, "name": "jorge" }
];

# use method ok and add object
output.ok(arrClientList)

# print output
print(output.__dict__)

#--------------------------
# result
# {
#     'success' : True,
#     'message' : 'ok',
#     'code' : 200,
#     'response' : [
#         { 'id':1, 'name': 'diana' },
#         { 'id':2, 'name': 'jorge' }
#     ]
# }

using http-based methods it is possible to shorten the previous sentence making it smaller and more readable

also can define another message:

# create default output from module connector
output = Moduleconnector( "another_default_message" )

# or
output.ok("hello_world")

Faileds methods

in this case using the badRequest() for send a success false response with code 400.

# for output with response and message (the order of the variables does not matter)
output.badRequest( arrClientList, "array_clients_list" )

#--------------------------
# result
# {
#     'success' : False,
#     'message' : 'array_clients_list',
#     'code' : 400,
#     'response' : [
#         { 'id':1, 'name': 'diana' },
#         { 'id':2, 'name': 'jorge' }
#     ]
# }

also if you don't have an object to add to your output you can just write the message (this also applies to successful responses)

# for output with message only
output.badRequest( "empty_response" )

#--------------------------
# result
# {
#     'success' : False,
#     'message' : 'empty_response',
#     'code' : 400,
#     'response' : []
# }

Methods

it is recommended that all requests with code 2XX are always true and that 3XX, 4XX and 5XX are always false

Method Name Success Code
.ok() true 200
.created() true 201
.accepted() true 202
.nonAuthoritative() true 203
.noContent() true 204
.badRequest() false 400
.unauthorized() false 401
.forbidden() false 403
.notFound() false 404
.conflict() false 409

python-module-connector's People

Contributors

jhonnattan123 avatar

Stargazers

 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.