http
This commit is contained in:
1
tools/ws/.gitignore
vendored
Normal file
1
tools/ws/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__/
|
2
tools/ws/api.py
Normal file
2
tools/ws/api.py
Normal file
@ -0,0 +1,2 @@
|
||||
def say_hello(name=None):
|
||||
return { "message": "Hello {}, from API!".format(name or "") }
|
29
tools/ws/heroes.py
Normal file
29
tools/ws/heroes.py
Normal file
@ -0,0 +1,29 @@
|
||||
HEROES = [
|
||||
{ "id": 1, "name": "Wolfgang" },
|
||||
{ "id": 2, "name": "Andreas" },
|
||||
{ "id": 3, "name": "Frank" },
|
||||
{ "id": 4, "name": "Thomas" },
|
||||
{ "id": 5, "name": "Barbara" },
|
||||
{ "id": 6, "name": "Robert" },
|
||||
{ "id": 7, "name": "Raphael" },
|
||||
{ "id": 8, "name": "Lucia" },
|
||||
{ "id": 9, "name": "Gregor" },
|
||||
]
|
||||
|
||||
|
||||
def get_hero(id=None):
|
||||
if id:
|
||||
try:
|
||||
hero = next(x for x in HEROES if x["id"] == id)
|
||||
return { "id": hero["id"], "name": hero["name"] }
|
||||
except StopIteration:
|
||||
return 'Hero not found', 404
|
||||
|
||||
|
||||
def get_heroes():
|
||||
if HEROES:
|
||||
return HEROES
|
||||
else:
|
||||
return 'No heroes available', 404
|
||||
|
||||
|
63
tools/ws/my_api.yaml
Normal file
63
tools/ws/my_api.yaml
Normal file
@ -0,0 +1,63 @@
|
||||
swagger: '2.0'
|
||||
info:
|
||||
title: Hello API
|
||||
version: "0.1"
|
||||
|
||||
paths:
|
||||
/greeting:
|
||||
get:
|
||||
operationId: api.say_hello
|
||||
summary: Returns a greeting
|
||||
parameters:
|
||||
- name: name
|
||||
in: query
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
description: Message greeting
|
||||
/hero:
|
||||
get:
|
||||
operationId: heroes.get_hero
|
||||
summary: Returns hero by id
|
||||
parameters:
|
||||
- name: id
|
||||
in: query
|
||||
type: integer
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
$ref: '#/definitions/Hero'
|
||||
404:
|
||||
description: Hero not found
|
||||
/heroes:
|
||||
get:
|
||||
operationId: heroes.get_heroes
|
||||
summary: Returns all heroes
|
||||
responses:
|
||||
200:
|
||||
description: Successful response.
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Hero'
|
||||
404:
|
||||
description: No heroes available
|
||||
|
||||
|
||||
definitions:
|
||||
Hero:
|
||||
description: Hero type
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
7
tools/ws/server.ini
Normal file
7
tools/ws/server.ini
Normal file
@ -0,0 +1,7 @@
|
||||
[uwsgi]
|
||||
http = :5000
|
||||
wsgi-file = server.py
|
||||
processes = 4
|
||||
threads = 2
|
||||
stats = 127.0.0.1:9191
|
||||
|
5
tools/ws/server.py
Normal file
5
tools/ws/server.py
Normal file
@ -0,0 +1,5 @@
|
||||
import connexion
|
||||
|
||||
app = connexion.App(__name__)
|
||||
app.add_api('my_api.yaml')
|
||||
application = app.app
|
Reference in New Issue
Block a user