11# -*- coding: utf-8 -*-
2- from flask import Flask , jsonify
2+ from flask import Flask , jsonify , request
33from flask_restful import Resource , Api
4- import joke
5- import sys
64from flask_cors import CORS
75
6+ import joke
7+
88app = Flask (__name__ )
99api = Api (app )
1010
@@ -15,28 +15,31 @@ class APP(Resource):
1515
1616 def get (self ):
1717 return jsonify ({
18- 'author' : 'Sameer Kumar' ,
19- 'author_url' : 'https://www.sameerkumar.website' ,
20- 'base_url' : 'https://geek-jokes.sameerkumar.website' ,
21- 'project_name' : 'Geek Joke API' ,
22- 'project_url' : 'https://github.com/sameerkumar18/geek-joke-api'
23- })
24-
18+ 'author' : 'Sameer Kumar' ,
19+ 'author_url' : 'https://www.sameerkumar.website' ,
20+ 'base_url' : 'https://geek-jokes.sameerkumar.website' ,
21+ 'project_name' : 'Geek Joke API' ,
22+ 'project_url' : 'https://github.com/sameerkumar18/geek-joke-api'
23+ })
2524
2625 def post (self ):
2726 jk = joke .get_joke ()
28- jk = jk .encode ('ascii' , 'ignore' ).decode ('ascii' )
29- #jk = jk.encode('utf-8')
30- return jk
27+ if request .args .get ('format' ) == 'json' :
28+ return {'joke' : jk }
29+ else :
30+ # Making sure existing clients don't break
31+ return jk
3132
3233
3334class API (Resource ):
3435
3536 def get (self ):
3637 jk = joke .get_joke ()
37- jk = jk .encode ('ascii' , 'ignore' ).decode ('ascii' )
38- # jk = jk.encode('utf-8')
39- return jk
38+ if request .args .get ('format' ) == 'json' :
39+ return {'joke' : jk }
40+ else :
41+ # Making sure existing clients don't break
42+ return jk
4043
4144
4245api .add_resource (APP , '/' )
0 commit comments