Skip to content

Commit

Permalink
Merge pull request #2432 from Herzogs/main
Browse files Browse the repository at this point in the history
Reto #10 API - Bash - C
  • Loading branch information
Roswell468 authored Mar 7, 2023
2 parents 312ed43 + 079b817 commit e8e221b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Retos/Reto #10 - LA API [Media]/bash/Herzogs.sh
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
31 changes: 31 additions & 0 deletions Retos/Reto #10 - LA API [Media]/c/Herzogs.c
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;
}

0 comments on commit e8e221b

Please sign in to comment.