Package: apys
apys - v3.1Wellcome to apys! A simple backend restful framework!LANGUAGEPython >= 3.4.2LIBRARIESaiohttp- http client/server for asyncioINSTALLATIONInstall python 3Windows -LinkUbuntu -sudo apt-get install pythonFedora -sudo yum install pythonArch -sudo pacman -S pythonInstall PIP - Python libraries managerWindows -LinkUbuntu -sudo apt-get install pipFedora -sudo yum install pipArch -sudo pacman -S pipInstall this framework using PIPpip install apysINITIALIZING PROJECT$ apys --initUSINGDIRECTORIES/config - json configuration files
/endpoints - backend endpoints
/filters - script files to execute before the endpoint  
/utils - script files to execute when server startsCONFIGHere are the configuration files used in the app.
They will be send to the endpoint via paramapi.configThere are 3 special file names:prod.json- The production configuration filedev.json- The development configuration filelocal.json- The local configuration file (ignore in git)You can also force it to use a configuration with the--configor-coption:$ apys -s --config=my_configNote: If no config file is chosen, they will work as following: the api tries to loadlocal.json, thendev.json, thenprod.jsonThe current config special properties are the following:{"log":{"file":{"debug":"string or false //default=false. debug log file, false for sys.stdout","error":"string or false //default=false. debug error file, false for sys.stderr","(...)":"string or false //optional. you can specify any other log file, but you will have to tell the `api.debug` function to use it"},"color":"bool //default=true"},"server":{"port":"int //default=8080","cors":"string or false //default=false"},"utils":["string //default=[]. list of utils in order to load"],"(...)":"(...) //you can add any other key and access it via `api.config['my_key']`"}You can also use environment variables
like$PORT(forPORTenv var), and set a default value if no env var is found
like$PORT|8080or$PORT|8080|int(if type is needed)ENDPOINTSThis will be your main dev dirAll files added here will be an endpoint automaticallyi.e.: the fileendpoints/hello/world.pywill generate an endpoint/hello/worldThe file's code will be the following:filters=['filter1',['filter2','filter3']]defmethod(req,api):pass# processWheremethodis the http request type:postgetputdeleteheadoptionsdefault - executed when a request is made for any of the above, but it is not implementedprocessis what you wan the endpoint to do (your code)filter1,filter2andfilter3are thefiltersscripts (without.py) executed before the endpoint is calledIf you put your filter inside an array the error they return will be returned only if ALL of them return some errorreqisaiohttp's request,documentationreq's propertybodyonly works for json works as of nowapiis the object that contains all api functionalities:config - Configuration dictionary used in the actual scopedebug - function to log messageserror - function to log errorsAlsoapi.webcontainsaiohttp.webFILTERSCode that will that will be called before every request.method(req, api) -methodbeing the type of http requestThe function that will be executed 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.always(req, api)The function that will be executed before any request.
Note: this function will be executed before the other filters.UTILSPython files special functionality.It needs to be inside a dir and has some special filesinit.pyThis file contains a function that will be called before initializing the api.definit(api):passThe function that will be executed on server startup
Only one time.Useful for setting some api constantscli.pyThis file contains a function that will add a commandline argument.The util flags will be--[util_name]and--[util_name_first_char]util name is test, so flags should be--testand-tclassCLI:def__init__(self,result):# See `parser.add_argument` doc for information on theseself.action='store_true'self.default=Falseself.help='It makes everything shine'# store the result of user inputself.result=resultdefstart(self,api,endpoints):passEXAMPLELook at thedemos/for examples:hello_world: a simple hello world app, to learn the basicscalculator: a simpler app that resembles more a normal productlog_to_file: an example of logging in filesuser_role: an advanced example on filtersunit_testing: an advanced example on adding cli argumentsSTARTING THE SERVERThere are 2 ways to start the serverExecuteapys -sfrom terminal on your root project folder (Recommended)Call the methodstart()from moduleapys.serverOBSERVATIONBoth the framework and this page are in development, so, subjected to changes.Version previous to v0.1.0 vas calledpypolybackand used python 2.