...
Code Block | ||
---|---|---|
| ||
from flask.views import MethodView class InformationAPI(MethodView): def get(self): information = Information.from_data(request.data) ... app.add_url_rule('/<info>/informations/', view_func=InformationAPI.as_view('informations')) |
falcon
Falcon routeannotations for web service operations (GET, PUT, POST, DELETE) are supported.
In the following example, a default GET operation is ascribed to the functionon_get from GetResourceclass,and the POST and PUT operations to the on_putandon_postfunctions fromPut_PostResourcewith two differents urls routing:
|
The link between the GET operation named after the routing URL "/" and the called functionon_get is represented by an arrow pointing to the function:
The name of a saved Web Service Operation object will be generated from the routing URL by adding a final slash when not present. In this example the name of the POST operations is "/url/example/1/" and "/url/example/2/" after the routing url "/url/example/1" and "/url/example/2".
Sinks are supported with the following rules : If no route matches a request, but the path in the requested URI matches a sink prefix, Falcon will pass control to the associated sink, regardless of the HTTP method requested. If the prefix overlaps a registered route template, the route will take precedence and mask the sink.
In this case Web Service Operation objects generated as sinks will be named as/that/, and not as/this/since another Web Service Operation object exists with an overlapping url.
|
The optionnal suffixkeyword argument of Falcon add_route is supported. In this way, multiple closely-related routes can be mapped to the same resource.
|
web2py
Example for GET request:
Code Block | ||
---|---|---|
| ||
from gluon.tools import fetch
page = fetch('http://www.google.com/')
|
Database access
PEP 249
Simple database queries consistent with the Python Database API Specification (PEP 249) are recognized. This allows to support a large number of important libraries interfacing Python and SQL databases (SQLite, MySQL, etc). The analyzer identifies execute method calls as potential database queries and searches for generic SQL statements passed in as an argument ('SELECT ...", "INSERT ...)". In the example below data from the stocks table is retrieved via a SELECT statement passed explicitly by a string to the execute method of a cursor object.
Code Block | ||
---|---|---|
| ||
# query.py import sqlite3 conn = sqlite3.connect('example.db') c = conn.cursor() c.execute('SELECT * FROM informations') |
In addition to execute method calls, the analyzer identifies raw method calls which are used in Django framework. SQL queries can be defined directly or via a method.
Code Block | ||
---|---|---|
| ||
from django.db import models ... def function(self): sql = 'SELECT * FROM informations' return model.objects.raw(sql) |
...