Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

0.fastapi_basic.py 722 B

You have to be logged in to leave a comment. Sign In
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
  1. # 1. Library imports
  2. import uvicorn
  3. from fastapi import FastAPI
  4. # 2. Create the app object
  5. app = FastAPI()
  6. # 3. Index route, opens automatically on http://127.0.0.1:8000
  7. @app.get('/')
  8. def index():
  9. return {'message': 'Hello, stranger'}
  10. # 4. Route with a single parameter, returns the parameter within a message
  11. # Located at: http://127.0.0.1:8000/AnyNameHere
  12. @app.get('/{name}')
  13. def get_name(name: str):
  14. return {'message': f'Hello, {name}'}
  15. @app.post('/students')
  16. def savestudents(name: str, lastname: str):
  17. return f"Estudiante {name} {lastname} guardado"
  18. # 5. Run the API with uvicorn
  19. # Will run on http://127.0.0.1:8000
  20. if __name__ == '__main__':
  21. uvicorn.run(app, host='127.0.0.1', port=8000)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...