FastAPI: Hello World

Posted by

FastApi Holi mundo

FastApi Holi mundo

FastApi is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. This article will guide you through creating a simple “Hello World” application using FastApi.

Hola mundo

Let’s create a basic “Hello World” application using FastApi.

    
    from fastapi import FastAPI

    app = FastAPI()

    @app.get("/")
    def read_root():
        return {"Hello": "World"}
    
    

In the code above, we import the FastAPI class from the fastapi module and create an instance of it. Then, we define a route “/” using the @app.get decorator and a function read_root that returns a JSON object {“Hello”: “World”}.

To run the application, you can use the uvicorn web server:

    
    uvicorn main:app --reload
    
    

Now, if you visit http://localhost:8000 in your browser, you should see the message {“Hello”: “World”} displayed on the screen.

Congratulations! You have successfully created a “Hello World” application using FastApi.

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@user-rt2fp9zo8g
3 months ago

¡Excelente tutorial!