Package: pypolyback
Wellcome to Pypoly Back! A simple backend restful framework!LANGUAGEPython 2.7LIBRARIEStwisted- Web event-handling
Framework (Low Level)cyclone- Http framework (High
Level)INSTALATIONInstall python 2.7Windows -LinkUbuntu -sudoapt-getinstall python2Fedora -sudo yum install python2Arch -sudo pacman-Spython2Install PIP - Python libraries managerWindows -LinkUbuntu -sudoapt-getinstall pip2Fedora -sudo yum install pip2Arch -sudo pacman-Spip2Install this framework using PIPpip2 install pypolybackINITIALIZATING PROJECT$ pypolyback --initUSINGDIRECTORIES/pypolyback (*) - api internal files
/config - json configuration files
/endpoints - backend endpoints
/utils - helper script files

Note (\*): The dir pypolyback will only exists if you didn't install
``pypolyback``'s library from pipAPIHere is present all api files that work behind the endpointsCONFIGHere are the configuration files used in the app. They will be send to
the endpoint via paramapi.configThere are 3 special filenames: *prod.json- The oficial
configuration file *dev.json- The development configuration file
*local.json- The local configuration file (ignore in git)Note: They really work as following: the api tries to loadlocal.json, thendev.json, thenprod.json. So in the
oficial release you will only haveprod.jsonThe current config special properties are the following:{"log":bool,//optional. default=False"server":{"port":int,//optional. default=8888"cors":stringorFalse//optional. default=False},"mail":{"host":string,"port":int,//optional. default=25 or 587 for TLS"tls":bool,//optional. default=False"username?":string,//optional. no default"password?":string//optional. no default}}ENDPOINTSThis will be your main dev dirAll files added here will be an endpoint automaticallyi.e.: the fileendpoints/test/helloworld.pywill generate an
endpoint/test/helloworldThe file’s code will be the following:utils=['[util1]','[util2]'][@async]def[method](req,api):[process]Where[method]is the http request type: * post * get * put *
delete * head * options * default - executed when a request is made
for any of the above, but it is not implemented[process]is what you wan the endpoint to do (your code)[util1]and[util2]are theutilsscripts (without.py)reqiscyclone’s request, with these properties included: *
params - arguments received from request, an object (primitive, list or
dictionary) * send - function to respond the request with an objectreq’s complete documentatios in present on cyclone’s sitehttp://cyclone.io/documentation/web.htmlapiis the object that contains all api functionalities: * config -
Configuration dictionary used in the actual scope * debug - function to
log messages * error - function to log errors[@async]is an optional annotation, that makes this method
asynchronous.Note: if async is used you will need to import it
(from pypolyback import async)asynccomplete doc is the same as twisted’sinlineCallbackhttps://twistedmatrix.com/documents/current/api/twisted.internet.defer.html#inlineCallbacksUTILSPython files with reusable code, to be called on endpoints.It will be a normal cod, but with some special funcions:init(api)The function that will be executed on server startup
Only one time.[method](req, api) -[method]being the type of http requestThe function that will be called before every request to the function with the same name on the endpoint.
Any result should be stored on the variable `req`, because it is the only local variable on the request.any(req, api)The function that will be executed before any request.
Note: thids function will be executed before the later.APP.pyThis file is not needed if you installed from pipAn executable to start your serverEXAMPLETo have a feeling of how things are working take a look at the fileendpoints/example/ex_endpoint.pyIt should be like this:#!/usr/bin/env python# -*- coding: utf-8 -*-frompypolybackimportasyncutils=['example_util']@async#método asíncronodefget(req,api):"""
    Start the server
    Then go, from your browser, in `localhost:8888/example/ex_endpoint`
    There shoud open a page with the content `Success in method get!`

    Output:
        string
    """result=yieldapi.example_util.write(req)#coletando dados de forma asíncronareq.send(result)#retornando os dadosdefpost(req,api):"""
    Start the server
    Then make a post http request to `localhost:8888/example/ex_endpoint`
    Sending the documented object as input
    It should be returned `{"message": input.message, "status":"Sucess in method post!"}`

    Input:
        message: string

    Output:
        message: string
        request: string
    """message=req.params['message']#coletando dados da requisição#retornando os dadosreq.send({'message':api.example_util.write(req),'request':message})Now follow instructions to test it and see how the endpoint worksSTARTING THE SERVERThere are 2 ways to start the serverExecutepypolyback--startfrom terminal on your root project
folder (Recomended)Call the methodstart()from modulepypolyback.server(Only
recomended if you need to do something before starting the server)OBSERVATIONBoth the framework and this page are in development, so, subjected to
changes.