Skip to main content

A Falcon Framework extension featuring Swagger, SQLAlchemy and Redis

Project description

[![Build Status](https://travis-ci.org/dutradda/falcon-swagger.svg?branch=master)](https://travis-ci.org/dutradda/falcon-swagger)
[![Coverage Status](https://coveralls.io/repos/github/dutradda/falcon-swagger/badge.svg?branch=master)](https://coveralls.io/github/dutradda/falcon-swagger?branch=master)

# falcon-swagger
A Falcon Framework (http://falconframework.org) Extension.

Features:
- Supports Swagger Schema 2.0 (OpenAPI 2.0);
- Provides SQLAlchemy models base classes (with Redis integration, if you want);
- Provides Redis models base classes (without SQLAlchemy).

Usage Example:

```python
from falconswagger import SwaggerAPI, ModelHttpMeta

class HelloModelMeta(ModelHttpMeta):
__schema__ = {
'/hello/you/{name}': {
'get': {
'parameters': [{
'name': 'name',
'in': 'path',
'required': True,
'type': 'string'
}],
'operationId': 'get_hello_you',
'responses': {'200': {'description': 'Got you'}}
}
},
'/hello/world': {
'get': {
'operationId': 'get_hello_world',
'responses': {'200': {'description': 'Got hello'}}
}
}
}

def get_hello_you(cls, req, resp):
you = req.context['parameters']['path']['name']
resp.body = 'Hello {}!\n'.format(you)

def get_hello_world(cls, req, resp):
resp.body = 'Hello World!\n'

class HelloModel(metaclass=HelloModelMeta):
pass

api = SwaggerAPI([HelloModel], title='Hello API')
```

```bash
gunicorn hello_word_api:api
```

```bash
curl -i localhost:8000/hello/world
```

```text
HTTP/1.1 200 OK
Server: gunicorn/19.6.0
Connection: close
content-length: 13
content-type: application/json; charset=UTF-8

Hello World!
```

```bash
curl -i localhost:8000/hello/you/Diogo
```

```text
HTTP/1.1 200 OK
Server: gunicorn/19.6.0
Connection: close
content-length: 13
content-type: application/json; charset=UTF-8

Hello Diogo!
```


```bash
curl -i localhost:8000/swagger.json
```

```json
HTTP/1.1 200 OK
Server: gunicorn/19.6.0
Connection: close
content-length: 672
content-type: application/json; charset=UTF-8

{
"swagger": "2.0",
"paths": {
"/hello/world": {
"get": {
"operationId": "HelloModel.get_hello_world",
"responses": {
"200": {
"description": "Got hello"
}
}
}
},
"/hello/you/{name}": {
"get": {
"operationId": "HelloModel.get_hello_you",
"responses": {
"200": {
"description": "Got you"
}
},
"parameters": [
{
"in": "path",
"type": "string",
"required": true,
"name": "name"
}
]
}
}
},
"info": {
"title": "Hello API",
"version": "1.0.0"
}
}
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

falcon-swagger-0.14.4.tar.gz (25.4 kB view details)

Uploaded Source

File details

Details for the file falcon-swagger-0.14.4.tar.gz.

File metadata

File hashes

Hashes for falcon-swagger-0.14.4.tar.gz
Algorithm Hash digest
SHA256 53676e75cca57898fa26b07aa4775904f9a47dfb65a779eb67895e3641f3c7ec
MD5 fb4e966b7150e00e89982f7fec48d7a1
BLAKE2b-256 8957751687292aaf5498d883aa0b76a305bffcc6564d7b6255ebfc58ff7b9526

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page