-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #2432 from Herzogs/main
Reto #10 API - Bash - C
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
curl -s -k -X GET https://www.fruityvice.com/api/fruit/banana |
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,31 @@ | ||
#include <stdio.h> | ||
#include <curl/curl.h> | ||
/* | ||
* Llamar a una API es una de las tareas más comunes en programación. | ||
* | ||
* Implementa una llamada HTTP a una API (la que tú quieras) y muestra su | ||
* resultado a través de la terminal. Por ejemplo: Pokémon, Marvel... | ||
* | ||
* Aquí tienes un listado de posibles APIs: | ||
* https://github.com/public-apis/public-apis | ||
*/ | ||
|
||
int main(void){ | ||
CURL *curl; | ||
CURLcode res; | ||
struct curl_slist *headers = NULL; | ||
headers = curl_slist_append(headers, "Content-Type: application/json"); | ||
headers = curl_slist_append(headers, "Accept: application/json"); | ||
curl = curl_easy_init(); | ||
if(curl) { | ||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); | ||
curl_easy_setopt(curl, CURLOPT_URL, "https://restcountries.com/v3.1/name/Argentina"); | ||
res = curl_easy_perform(curl); | ||
if(res != CURLE_OK) | ||
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); | ||
curl_easy_cleanup(curl); | ||
} | ||
curl_slist_free_all(headers); | ||
return 0; | ||
} | ||
|