-
Notifications
You must be signed in to change notification settings - Fork 50
/
app.py
49 lines (36 loc) · 1.11 KB
/
app.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
# -*- coding: utf-8 -*-
from flask import Flask, jsonify, request
from flask_restful import Resource, Api
from flask_cors import CORS
import joke
app = Flask(__name__)
api = Api(app)
CORS(app)
class APP(Resource):
def get(self):
return jsonify({
'author': 'Sameer Kumar',
'author_url': 'https://www.sameerkumar.website',
'base_url': 'https://geek-jokes.sameerkumar.website',
'project_name': 'Geek Joke API',
'project_url': 'https://github.com/sameerkumar18/geek-joke-api'
})
def post(self):
jk = joke.get_joke()
if request.args.get('format') == 'json':
return {'joke': jk}
else:
# Making sure existing clients don't break
return jk
class API(Resource):
def get(self):
jk = joke.get_joke()
if request.args.get('format') == 'json':
return {'joke': jk}
else:
# Making sure existing clients don't break
return jk
api.add_resource(APP, '/')
api.add_resource(API, '/api')
if __name__ == '__main__':
app.run(debug=False)