Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
fastapi
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Roman Desyatskii
fastapi
Commits
0d2e0511
Commit
0d2e0511
authored
Jan 04, 2024
by
Roman Desyatskii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created router
parent
97dec368
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
router.py
src/app/api/router.py
+40
-0
No files found.
src/app/api/router.py
0 → 100644
View file @
0d2e0511
from
typing
import
Annotated
import
fastapi
from
fastapi
import
APIRouter
,
Path
from
pydantic
import
BaseModel
router
=
APIRouter
(
prefix
=
'/api'
)
class
Item
(
BaseModel
):
name
:
str
description
:
str
|
None
=
None
price
:
float
tax
:
float
|
None
=
None
@
router
.
post
(
'/items/'
)
async
def
create_item
(
item
:
Item
):
return
item
@
router
.
put
(
'/items/{item_id}'
)
async
def
put_item
(
item_id
:
Annotated
[
int
,
Path
(
title
=
"The ID of the item to get"
,
ge
=
0
,
le
=
1000
)],
q
:
str
|
None
=
None
,
item
:
Item
|
None
=
None
,
):
results
=
{
"item_id"
:
item_id
}
if
q
:
results
.
update
({
'q'
:
q
})
if
item
:
results
.
update
({
"item"
:
item
})
return
results
@
router
.
get
(
'hello-name/{name}'
)
async
def
get_hello_name
(
name
:
str
=
fastapi
.
Path
(
...
,
title
=
'Title name!'
),
):
return
{
'response'
:
f
'Hello {name} glad to see you!'
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment