Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Your First Async Function | The Asyncio Foundation
Python Asyncio in Depth
Sección 1. Capítulo 7
single

single

Challenge: Your First Async Function

Desliza para mostrar el menú

You are working with the public API jsonplaceholder.typicode.com, which provides fake data for testing and learning. Your task is to fetch user information and display it in a readable format.

The endpoint https://jsonplaceholder.typicode.com/users/{user_id} returns a JSON object with the following fields:

  • name: the user's full name;
  • email: the user's email address;
  • company: an object with a name field containing the company name.
Tarea

Desliza para comenzar a programar

  1. Define an async function fetch_user(client, user_id) that:
    • Sends a GET request to the users endpoint using the provided client and user_id;
    • Extracts name, email, and company name from the response;
    • Prints them in the format: Name | Email | Company.
  2. Define an async function main() that:
    • Creates an httpx.AsyncClient;
    • Uses asyncio.gather() to fetch users with IDs 1, 2, and 3 concurrently.
  3. Run main() using asyncio.run().

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 7
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt