listed_todo = api.model( "ListedTodo", { "id": fields.String(required=True, description="The todo ID"), "todo": fields.Nested(todo, description="The Todo"), }, ) def abort_if_todo_doesnt_exist(todo_id): if todo_id not in TODOS: api.abort(404, "Todo {} doesn't exist".format(todo_id)) parser = api.parser() parser.add_argument("task", type=str, required=True, help="The task details", location="form") @ns.route("/<string:todo_id>") @api.doc(responses={404: "Todo not found"}, params={"todo_id": "The Todo ID"}) class Todo(Resource): """Show a single todo item and lets you delete them""" @api.doc(description="todo_id should be in {0}".format(", ".join(TODOS.keys()))) @api.marshal_with(todo) def get(self, todo_id): """Fetch a given resource""" abort_if_todo_doesnt_exist(todo_id) return TODOS[todo_id]
""" Initialize Flask app """ from flask import Flask, g from flask.ext.restplus import Api from config import config app = Flask('application') api = Api(app, catch_all_404s=True, title='Rest Engine API', description='A simple API running on Google App Engine') from app.user.resources import * from app.user.models import User token_parser = api.parser() token_parser.add_argument( 'X-Session-Token', type=str, location='headers' ) @app.before_request def current_user(): args = token_parser.parse_args() token = args['X-Session-Token'] valid, data = User.verify_session_token(token) g.user = None if valid: if not data.get('password_reset'): g.user = User.get_by_id(data.get('user_id'))
class CraneInst(Resource): @api.doc(description='Install docker-crane') @api.response(500, 'Error processing the request', errorResponseModel) @api.response(200, 'OK', generalResponseModel) def get(self): try: return Installator.crane() except ControllerError as e: return controller_error(e.message) except Exception as e: return process_error(str(e)) # Deploy deployArgs = api.parser() deployArgs.add_argument('package', type=FileStorage, help='Package to be deployed', location='files') deploy_ns = api.namespace('deploy', description='Deploy packages.') @deploy_ns.route('/') class DeployService(Resource): @api.doc(description='Deploy service', parser=deployArgs) @api.response(500, 'Error processing the request', errorResponseModel) @api.response(200, 'OK', generalResponseModel) def post(self): try:
def shutdown(): scheduler.shutdown() def my_import(name): components = name.split('.') mod = __import__(components[0]) for comp in components[1:]: mod = getattr(mod, comp) return mod atexit.register(shutdown) parser = api.parser() parser.add_argument('name', required=True, help="Name is required", location="json") parser.add_argument('task_class', required=True, help="Task Class is required", location="json") parser.add_argument('minute', type=int) parser.add_argument('hour', type=int) parser.add_argument('day', type=int) parser.add_argument('month', type=int) parser.add_argument('day_of_week') parser.add_argument('start_date')
@api.doc(description='Dummy function. Returns a simple json with a message.') def get(self): return {'message':'I\'m alive'} @extra_ns.route('/check') class Check(Resource): @api.doc(description='Check several parameters in Crane status.') def get(self): from toolbox import docker dockerStatus = docker.checkDocker() return {'docker': 'correct' if dockerStatus==True else dockerStatus } dockerInfoArgs = api.parser() dockerInfoArgs.add_argument('endpoint', help='Docker daemon endpoint', location='form') @extra_ns.route('/dockerInfo') class DockerInfo(Resource): @api.doc(description='Retrieve information about the docker daemon provided by "endpoint".', parser=dockerInfoArgs) def post(self): try: return managementOps.getDockerInfo(request.form['endpoint']) except Exception, e: return e # Build API builder_ns = api.namespace('builder', description='Building related operations')
@api.doc( description='Dummy function. Returns a simple json with a message.') def get(self): return {'message': 'I\'m alive'} @extra_ns.route('/check') class Check(Resource): @api.doc(description='Check several parameters in Crane status.') def get(self): from toolbox import docker dockerStatus = docker.checkDocker() return {'docker': 'correct' if dockerStatus == True else dockerStatus} dockerInfoArgs = api.parser() dockerInfoArgs.add_argument('endpoint', help='Docker daemon endpoint', location='form') @extra_ns.route('/dockerInfo') class DockerInfo(Resource): @api.doc( description= 'Retrieve information about the docker daemon provided by "endpoint".', parser=dockerInfoArgs) def post(self): try: return managementOps.getDockerInfo(request.form['endpoint']) except Exception, e:
'api', __name__) @service.route('/') def index(): return render_template("index.html") api = Api(service, title='INSEE/IRIS Geolocalizer', ui=False, version='0.1', description="Retrieve some data related to the IRIS codes. Look for an IRIS from an address.") iris_code_parser = api.parser() iris_code_parser.add_argument("limit", required=False, default=10, dest='limit', location='args', help='Limit') address_parser = api.parser() address_parser.add_argument("q", required=True, dest='q', location='args', help='Query') IRIS_MODEL = OrderedDict([('iris', fields.String), ('city', fields.String), ('citycode', fields.String), ('name', fields.String), ('complete_code', fields.String), ('type', fields.String)]) ADDRESS_MODEL = IRIS_MODEL.copy() ADDRESS_MODEL["address"] = fields.String
'first_name': fields.String(required=False, description='The firstname of the user.', default=""), 'last_name': fields.String(required=False, description='The lastname of the user.', default=""), 'userid': fields.String(required=True, description='The userid of the user.'), 'groups': fields.List(fields.String, required=False, description='A list of groups the user belongs to.', default=[""]) }) group = api.model('group', { 'name': fields.String(required=True, description='The name of the group.') }) group_update = api.model('group_update', { 'members': fields.List(fields.String, required=True, description='Updated membership list for the specified group.') }) user_parser = api.parser() user_parser.add_argument('first_name', type=str, required=False, help='The firstname of the user.') user_parser.add_argument('last_name', required=False, help='The lastname of the user.') user_parser.add_argument('userid', required=True, help='The userid of the user.') user_parser.add_argument('groups', action='append', help='A list of groups the user belongs to.') group_parser = api.parser() group_parser.add_argument('name', type=str, required=True, help='The name of a group to add.') group_update_parser = api.parser() group_update_parser.add_argument('members', action='append', help='The list of users to add to this group.') class DAO(GroupDAO, UserDAO): def __init__(self): super(DAO, self).__init__()
if not album: api.abort(404, "Album id '{}' not found".format(album_id)) return album[0] def delete(self, album_id): album = _query("SELECT * FROM albums WHERE id=?", album_id) if not album: api.abort(404, "Album id '{}' not found".format(album_id)) else: with sqlite3.connect(DBFILE) as cnx: cu = cnx.cursor() cu.execute("DELETE FROM albums WHERE id=?", (album_id,)) cnx.commit() return '', 204 search_parser = api.parser() search_parser.add_argument("q", required=True, dest='q', location='args', help='Query') search_parser.add_argument("limit", default=10, type=int, required=False, dest='limit', location='args', help='Query') @api.route("/artist") class SearchAritst(Resource): @api.doc(parser=search_parser, description="search album from an artist") @api.marshal_with(MODEL) def get(self): args = search_parser.parse_args() name = args['q'] Logger.info("Look for '%s'", name)
if not os.path.exists(s.DIR_WIZARD): wizard.download() if not os.path.exists(s.DIR_WIZARD): raise Exception("Cannot get wizard.") # Write launch script for packages wizard.createLaunchScript() # Set Flask app = Flask(__name__, static_url_path="") api = Api(app, version="0.3", title="ComCloud-packager", description="API for the packaging-engine") namespace = api.namespace("v1", description="v1") downloads = api.namespace("downloads", description="downloads") newPackArgs = api.parser() newPackArgs.add_argument("requestToken", location="form") newPackArgs.add_argument( "recipes", type=FileStorage, help="Tar archive that contains the recipes and related data following some rules.", location="files", ) packprocessInfo = {"status": fields.String, "description": fields.String, "percentage": fields.Integer} packprocessInfoModel = api.model("packprocessInfo", packprocessInfo) @namespace.route("/recipe") class PackageService(Resource):
# required for task id generation import uuid app = Flask(__name__, static_folder='static') # swagger init blueprint = Blueprint('api', __name__) api = Api(blueprint, title='Tasks API', ui=False) # tasks persisted in the app scope TASKS = dict() # create parser initialization createParser = api.parser() createParser.add_argument('label', help='Task label', type=str, location='form', required=True) @api.route('/tasks') class TaskList(Resource): def get(self): """ Return all tasks """ return TASKS.values() @api.doc(parser=createParser) def post(self): """ Create new task
@install_ns.route('/crane') class CraneInst(Resource): @api.doc(description='Install docker-crane') @api.response(500, 'Error processing the request', errorResponseModel) @api.response(200, 'OK', generalResponseModel) def get(self): try: return Installator.crane() except ControllerError as e: return controller_error(e.message) except Exception as e: return process_error(str(e)) # Deploy deployArgs = api.parser() deployArgs.add_argument('package', type=FileStorage, help='Package to be deployed' , location='files') deploy_ns = api.namespace('deploy', description='Deploy packages.') @deploy_ns.route('/') class DeployService(Resource): @api.doc(description='Deploy service', parser=deployArgs) @api.response(500, 'Error processing the request', errorResponseModel) @api.response(200, 'OK', generalResponseModel) def post(self): try: return Deploy.new(request.files['package']) except ControllerError as e: return controller_error(e.message) except Exception as e:
url_prefix='/pyris' ) @service.route('/') def index(): return render_template("index.html") api = Api(service, title='INSEE/IRIS Geolocalizer', ui=False, version='0.1', description="Retrieve some data related to the IRIS codes. Look for an IRIS from an address.") apidoc.apidoc.static_url_path = service.url_prefix + apidoc.apidoc.static_url_path iris_code_parser = api.parser() iris_code_parser.add_argument("limit", required=False, default=10, dest='limit', location='args', help='Limit') address_parser = api.parser() address_parser.add_argument("q", required=True, dest='q', location='args', help='Query') IRIS_MODEL = OrderedDict([('iris', fields.String), ('city', fields.String), ('citycode', fields.String), ('name', fields.String), ('complete_code', fields.String), ('type', fields.String)]) ADDRESS_MODEL = IRIS_MODEL.copy() ADDRESS_MODEL["address"] = fields.String
'bower/bootstrap/dist/css/bootstrap.min.css', 'bower/fontawesome/css/font-awesome.min.css', 'bower/leaflet/dist/leaflet.css', 'css/main.css', ) @blueprint.route('/doc/', endpoint='doc') def swagger_ui(): return apidoc.ui_for(api) app.register_blueprint(blueprint) app.register_blueprint(apidoc.apidoc) # only needed for assets and templates # Query parameters parser for /stations stations_parser = api.parser() stations_parser.add_argument('limit', type=int, required=False, location='args', help='Query limit') stations_parser.add_argument('type', type=str, required=False, location='args', help='Station type: background, traffic, industrial or unknown') stations_parser.add_argument('country', type=str, required=False, location='args', help='Specify a country') # Query parameters parser for /countries countries_parser = api.parser() countries_parser.add_argument('limit', type=int, required=False, location='args', help='Query limit') def custom_cssmin(_in, out, **kw): out.write(cssmin(_in.read()))
from flask import Flask from flask.ext.restplus import Api, Resource, fields app = Flask(__name__) api = Api(app, version='1.0', title='Resume Generator API', description='An API used to integrate resume information from various formats and transform them into different graphical representations.') ns = api.namespace('resumes', description='Resumes') resume_parser = api.parser() resume_parser.add_argument('username', type=str, required=True, help='Your username, used as an identifier for any request to the API', location='form') resume_parser.add_argument('fullname', type=str, required=True, help='Your full name', location='form') resume_parser.add_argument('age', type=int, required=True, help='Your age', location='form') resume = api.model('Resume', { 'username': fields.String(required=True), 'fullname': fields.String(required=True), 'age' : fields.Integer(required=True) }) SUPPORTED_INPUTS = ['json'] resume_content_parser = api.parser() resume_content_parser.add_argument('content', type=str, required=True, help='The resume content in the format described by content_type.', location='form') resume_content_parser.add_argument('content_type', type=str, required=True, help='The resume content type submitted. Currently supported: ' + ', '.join(SUPPORTED_INPUTS), location='form') resume_content = api.model('ResumeContent', { 'content' : fields.String(required=True), 'content_type' : fields.String(required=True, enum=SUPPORTED_INPUTS), })
from flask import Flask, render_template, Blueprint, url_for from flask import request from flask import json from flask import Response from flask import jsonify from flask.ext.restplus import Api, Resource, apidoc import pprint import initSearch app = Flask(__name__) blueprint = Blueprint('api', __name__) api = Api(blueprint, title='Tasks API', ui=False) createParser = api.parser() createParser.add_argument('query', type=str) createParser.add_argument('command', type=str) # print(initSearch.getterms()) @api.route('/') class Index(Resource): @api.doc(parser=createParser) def post(self): """ depends on what is request is command or search call appropriate method """ args = createParser.parse_args() print(args['command']) print(args['query']) if args['command'] != None: