-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrp.py
More file actions
executable file
·42 lines (30 loc) · 1 KB
/
rp.py
File metadata and controls
executable file
·42 lines (30 loc) · 1 KB
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
# tanpa Marshmallow
from flask import Flask, request
from flask_restplus import Resource, Api, fields
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root@localhost:3306/resep'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
api = Api(app)
a_language = api.model('Language',
{
'language' : fields.String('The language.'),
'id' : fields.Integer('Id')
}
)
languages = []
python = {'language':'python', 'id':1}
languages.append(python)
@api.route('/language')
class Language(Resource):
@api.marshal_with(a_language, envelope='lanhuages')
def get(self):
return languages
@api.expect(a_language)
def post(self):
new_language = api.payload
new_language['id'] = len(languages)+1
languages.append(new_language)
return {'result':'language added.'}
if __name__ == '__main__':
app.run(debug=True)