-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (49 loc) · 1.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask
import requests
from flask_cors import CORS
from flask_restful import Resource, Api
from apispec import APISpec
from marshmallow import Schema, fields
from apispec.ext.marshmallow import MarshmallowPlugin
from flask_apispec.extension import FlaskApiSpec
from flask_apispec.views import MethodResource
from flask_apispec import marshal_with, doc, use_kwargs
app = Flask(__name__)
api = Api(app)
CORS(app, support_credentials=True)
app.config.update({
'APISPEC_SPEC': APISpec(
title='Get PokeMon starting with S',
version='v1',
plugins=[MarshmallowPlugin()],
openapi_version='2.0.0'
),
'APISPEC_SWAGGER_URL': '/swagger/', # URI to access API Doc JSON
'APISPEC_SWAGGER_UI_URL': '/swagger-ui/' # URI to access UI of API Doc
})
docs = FlaskApiSpec(app)
class ResponseSchema(Schema):
message = fields.Str(default='Success')
class API(MethodResource, Resource):
@doc(description='Get Pokemons that start with S', tags=['Pokemon Data'])
# @marshal_with(ResponseSchema)
def get(self):
'''
Get method represents a GET API method
'''
pokemons = get_pokemons()
return {'pokemons': pokemons}, 200
api.add_resource(API, '/get-pokemon')
docs.register(API)
def get_pokemons():
check_val = 'S'
data = requests.get('https://pokeapi.co/api/v2/type/11/').json()
pokemons = data['pokemon']
pokemon_data = list()
for val in pokemons:
pokemon = val['pokemon']['name']
if pokemon.startswith(check_val.lower()):
pokemon_data.append(pokemon)
return pokemon_data
if __name__ == '__main__':
app.run(debug=True, port=5000)