Skip to content

Commit dad0024

Browse files
committed
chore(python): modify post, put and delete endpoints to return 204 status instead of 200
Part of #16
1 parent 27ffed4 commit dad0024

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

examples/python/routes.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from fastapi import APIRouter, Depends, HTTPException
55

6+
from starlette import status
7+
68
from db import db_connection
79

810
router = APIRouter()
@@ -81,7 +83,7 @@ def get_list_v1_categories(limit, conn=Depends(db_connection)):
8183
conn.close()
8284

8385

84-
@router.post('/v1/categories')
86+
@router.post('/v1/categories', status_code = status.HTTP_204_NO_CONTENT)
8587
def post_v1_categories():
8688
pass
8789

@@ -108,11 +110,11 @@ def get_v1_categories_category_id(categoryId, conn=Depends(db_connection)):
108110
conn.close()
109111

110112

111-
@router.put('/v1/categories/{categoryId}')
113+
@router.put('/v1/categories/{categoryId}', status_code = status.HTTP_204_NO_CONTENT)
112114
def put_v1_categories_category_id():
113115
pass
114116

115117

116-
@router.delete('/v1/categories/{categoryId}')
118+
@router.delete('/v1/categories/{categoryId}', status_code = status.HTTP_204_NO_CONTENT)
117119
def delete_v1_categories_category_id():
118120
pass

src/templates/routes.py.ejs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import psycopg2.extras
33

44
from fastapi import APIRouter, Depends, HTTPException
55

6+
from starlette import status
7+
68
from db import db_connection
79

810
router = APIRouter()
@@ -120,7 +122,7 @@ def <%- pythonMethodName %>(<%- methodArgs.join(', ') %>):
120122
if (method.name === 'post') {
121123
%>
122124
123-
@router.post('<%- path %>')
125+
@router.post('<%- path %>', status_code = status.HTTP_204_NO_CONTENT)
124126
def <%- pythonMethodName %>():
125127
pass
126128
<%
@@ -129,7 +131,7 @@ def <%- pythonMethodName %>():
129131
if (method.name === 'put') {
130132
%>
131133
132-
@router.put('<%- path %>')
134+
@router.put('<%- path %>', status_code = status.HTTP_204_NO_CONTENT)
133135
def <%- pythonMethodName %>():
134136
pass
135137
<%
@@ -138,7 +140,7 @@ def <%- pythonMethodName %>():
138140
if (method.name === 'delete') {
139141
%>
140142
141-
@router.delete('<%- path %>')
143+
@router.delete('<%- path %>', status_code = status.HTTP_204_NO_CONTENT)
142144
def <%- pythonMethodName %>():
143145
pass
144146
<%

0 commit comments

Comments
 (0)