-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from josemoracard/jose3-exercises
todos los ejercicios, .gitignore, learn.json
- Loading branch information
Showing
75 changed files
with
599 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
!/exercises | ||
!/exercises/* | ||
exercises/*/__pycache__/ | ||
|
||
!/.learn | ||
/.learn/** | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# `00` Welcome to Python API Requests! | ||
|
||
Python Requests es una herramienta potente y ampliamente utilizada para interactuar con APIs y realizar solicitudes HTTP en aplicaciones Python. Simplifica el proceso de enviar solicitudes HTTP y manejar respuestas, convirtiΓ©ndose en una herramienta favorita entre los desarrolladores para integrarse con servicios web y obtener datos de APIs. | ||
|
||
Con Python Requests, puedes hacer fΓ‘cilmente solicitudes GET, POST, PUT, DELETE para comunicarte con servidores web y obtener datos. Admite el manejo de autenticaciΓ³n, encabezados, cookies y sesiones, permitiendo una integraciΓ³n sin problemas con diversos servicios web. | ||
|
||
AquΓ aprenderΓ‘s: | ||
|
||
1. ΒΏCΓ³mo hacer solicitudes GET? | ||
2. ΒΏCΓ³mo obtener propiedades de datos e informaciΓ³n? | ||
3. ΒΏCΓ³mo configurar request headers? | ||
4. ΒΏCΓ³mo configurar request content-type? | ||
5. ΒΏCΓ³mo hacer solicitudes POST? | ||
|
||
Haga clic en el botΓ³n `Next β` en la esquina superior derecha para continuar. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# `00` Welcome to Python API Requests! | ||
|
||
Python Requests is a powerful and widely-used package for interacting with APIs and performing HTTP requests in Python applications. It simplifies the process of sending HTTP requests and handling responses, making it a favorite tool among developers for integrating with web services and fetching data from APIs. | ||
|
||
With Python Requests, you can easily make GET, POST, PUT, DELETE, to communicate with web servers and retrieve data. It supports handling authentication, headers, cookies, and sessions, allowing for seamless integration with various web services. | ||
|
||
Here you will learn: | ||
|
||
1. How to do GET requests? | ||
2. How to fetch data properties and information? | ||
3. How to set request headers? | ||
4. How to set request content-type? | ||
5. How to do POST requests? | ||
|
||
Click the `Next β` button on the top right to continue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# `01` Creating a Request | ||
|
||
Python tiene integrado un [paquete de solicitudes (*requests package*)](https://requests.readthedocs.io/en/master/) eso permite a los desarrolladores crear solicitudes HTTP con bastante facilidad. | ||
|
||
AsΓ es como en Python hacemos una solicitud HTTP GET: | ||
|
||
```python | ||
response = requests.get('<destination url>') | ||
print(response.status_code) | ||
``` | ||
|
||
## π Instrucciones: | ||
|
||
Actualiza la variable `url` para que solicite a esta direcciΓ³n: | ||
|
||
```bash | ||
https://assets.breatheco.de/apis/fake/sample/hello.php | ||
``` | ||
|
||
> Nota: La consola debe imprimir un cΓ³digo de estado 200. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import requests | ||
|
||
url = "https://assets.breatheco.de/apis/fake/sample/hello.php" | ||
response = requests.get(url) | ||
|
||
print("The response status is: "+str(response.status_code)) |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
# `02` Manejar el Status de Respuesta | ||
# `02` Handle Response Status | ||
|
||
La siguiente solicitud GET siempre devuelve un cΓ³digo de status diferente, nunca se sabe quΓ© respuesta estΓ‘ recibiendo del servidor. | ||
|
||
## πInstrucciones | ||
## π Instrucciones: | ||
|
||
Crea una condiciΓ³n para imprimir en la consola los siguientes mensajes segΓΊn el status de respuesta: | ||
|
||
| Status | Message | | ||
| Status | Mensaje | | ||
| ----- | ----- | | ||
| 404 | The URL you asked is not found | | ||
| 404 | The URL you asked for is not found | | ||
| 503 | Unavailable right now | | ||
| 200 | Everything went perfect | | ||
| 400 | Something is wrong on the request params | | ||
| 400 | Something is wrong with the request params | | ||
| Otro cΓ³digo de status | Unknown status code | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# `02` Handle Response Status | ||
|
||
The following GET request is always returning a different status code, you never know what reponse you are getting form the server. | ||
The following GET request is always returning a different status code; you never know what response you are getting from the server. | ||
|
||
## πInstructions | ||
## π Instructions: | ||
|
||
Create a condition to print on the console the following messages depending on the response status: | ||
Create a condition to print on the console the following messages, depending on the response status: | ||
|
||
| Status | Message | | ||
| ----- | ----- | | ||
| 404 | The URL you asked is not found | | ||
| 404 | The URL you asked for is not found | | ||
| 503 | Unavailable right now | | ||
| 200 | Everything went perfect | | ||
| 400 | Something is wrong on the request params | | ||
| anything else | anything | | ||
| 400 | Something is wrong with the request params | | ||
| Any other code | Unknown status code | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import requests | ||
|
||
response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php") | ||
|
||
if response.status_code == 404: | ||
print("The URL you asked for is not found") | ||
elif response.status_code == 503: | ||
print("Unavailable right now") | ||
elif response.status_code == 200: | ||
print("Everything went perfect") | ||
elif response.status_code == 400: | ||
print("Something is wrong with the request params") | ||
else: | ||
print("Unknown status code") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
# `03` Respuesta en Body | ||
# `03` Response Body | ||
|
||
Haga clic en este enlace para ver la respuesta que esta solicitud GET estΓ‘ dando en el body: | ||
[https://assets.breatheco.de/apis/fake/sample/random-status.php](https://assets.breatheco.de/apis/fake/sample/random-status.php) | ||
|
||
Ahora, si deseas obtener ese body como respuesta (texto), todo lo que tiene que hacer es: | ||
Ahora, si deseas obtener el *body* de la respuesta (texto/contenido), todo lo que tienes que hacer es: | ||
|
||
```py | ||
# plain text | ||
print(response.text) | ||
``` | ||
|
||
# π Instrucciones | ||
## π Instrucciones: | ||
|
||
Imprime en la consola el *body* de la respuesta solo para solicitudes con status `200`, para el resto imprime: | ||
|
||
Imprime en la consola la the responde body solo para solicitudes 200, para el resto imprima "Something went wrong". | ||
```text | ||
"Something went wrong" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import requests | ||
|
||
url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" | ||
url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import requests | ||
|
||
url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" | ||
|
||
response = requests.get(url) | ||
|
||
if response.status_code == 200: | ||
print(response.text) | ||
else: | ||
print("Something went wrong") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.