Escriu per cercar…

Basic

Aquesta pàgina encara no s'ha traduït — es mostra en l'idioma original:English

Introduction

HTTPX is a powerful and user-friendly HTTP client that allows developers to make HTTP requests with ease.

It offers support for asynchronous programming, HTTP/2, and connection pooling.

Getting Started

Clone the httpx-basic project:

ps
git clone https://gitlab.com/xtec/python/httpx-basic.git

Start the FastAPI server:

ps
cd httpx-basic
uv run app/main.py

Open the client.py file that is on the project root:

python
client.py
import json

import httpx


def main():

    response = httpx.get('http://localhost:8000/person/1')
    data = response.json()
    print(json.dumps(data, indent=4))


if __name__ == "__main__":
    main()

This script imports the httpx package and makes a GET request to the endpoint http://localhost:8000/person/1

Run this script; you should observe output similar to the following:

json
{
    "id": 1,
    "name": "David",
    "surname": "de Mingo"
}

Estàs llegint una vista prèvia.

Inicia sessió per llegir l'article complet. Qualsevol compte obre 4 articles gratuïts al mes; l'alumnat i el professorat llegeixen les pàgines del seu curs sense límit.

Inicia sessió