FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flask-api/example.py at develop · flask-api/flask-api · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
flask-api
/
flask-api
Public
Notifications
You must be signed in to change notification settings
Fork
196
Star
1.5k
Code
Issues
15
Pull requests
3
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
flask-api
/
example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (43 loc) · 1.29 KB
Breadcrumbs
flask-api
/
example.py
Copy path
File metadata and controls
57 lines (43 loc) · 1.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
flask
import
request
,
url_for
from
flask
.
ext
.
api
import
FlaskAPI
,
exceptions
,
status
app
=
FlaskAPI
(
__name__
)
notes
=
{
0
:
"do the shopping"
,
1
:
"build the codez"
,
2
:
"paint the door"
,
}
def
note_repr
(
key
):
return
{
"url"
:
request
.
host_url
.
rstrip
(
"/"
)
+
url_for
(
"notes_detail"
,
key
=
key
),
"text"
:
notes
[
key
],
}
@
app
.
route
(
"/"
,
methods
=
[
"GET"
,
"POST"
])
def
notes_list
():
"""
List or create notes.
"""
if
request
.
method
==
"POST"
:
note
=
str
(
request
.
data
.
get
(
"text"
,
""
))
idx
=
max
(
notes
.
keys
())
+
1
notes
[
idx
]
=
note
return
note_repr
(
idx
),
status
.
HTTP_201_CREATED
# request.method == 'GET'
return
[
note_repr
(
idx
)
for
idx
in
sorted
(
notes
.
keys
())]
@
app
.
route
(
"/<int:key>/"
,
methods
=
[
"GET"
,
"PUT"
,
"DELETE"
])
def
notes_detail
(
key
):
"""
Retrieve, update or delete note instances.
"""
if
request
.
method
==
"PUT"
:
note
=
str
(
request
.
data
.
get
(
"text"
,
""
))
notes
[
key
]
=
note
return
note_repr
(
key
)
elif
request
.
method
==
"DELETE"
:
notes
.
pop
(
key
,
None
)
return
""
,
status
.
HTTP_204_NO_CONTENT
# request.method == 'GET'
if
key
not
in
notes
:
raise
exceptions
.
NotFound
()
return
note_repr
(
key
)
if
__name__
==
"__main__"
:
app
.
run
(
debug
=
True
)
Back
|
FazBrowse Home
|
New Git URL