0Pricing
Arduino & IoT Academy · Aula

Obtenha dados de uma API com GET

Faça uma solicitação HTTP e leia a resposta.

Obtenha dados de uma API com GET é uma aula grátis de Arduino & IoT Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Arduino & IoT Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Arduino & IoT Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

The Web Is Just Requests

Your board can pull data from the internet the same way a browser does: by making an HTTP request to a URL. 🌐

What GET Means

A GET request asks a server, please send me this data. It only reads, it never changes anything on the other side.

You Need a Connection First

Before any request, your ESP must already be on WiFi. Without a network connection there is nowhere to send the request.

Include HTTPClient

The HTTPClient library gives you simple functions to make requests. Include it at the top of your sketch.

#include <HTTPClient.h>

Create the Client

Make an HTTPClient object, then point it at your target URL with begin(). This sets up the request you are about to send.

HTTPClient http;
http.begin("http://api.example.com/data");

Send the GET

Call GET() to fire the request. It returns an HTTP status code that tells you whether the server liked your request.

int code = http.GET();

Check the Status Code

A code of 200 means success. Always check it before trusting the data, since 404 or 500 means something went wrong.

if (code == 200) {
  // good response
}

Read the Response Body

When the status is good, grab the actual data with getString(). This is the text the server sent back to you.

String body = http.getString();

Always Free the Connection

Call end() when you are done. This closes the connection and frees memory so the next request starts clean.

http.end();

Negative Codes Are Local

A negative status code does not come from the server. It means the request failed on your side, often no WiFi or a bad URL.

Do Not Hammer the Server

Add a delay between requests so you do not flood the API. Most services limit how often you may ask for data.

Quick Check

Your code received an HTTP status of 200. What does that tell you?

Recap

You connected, called GET(), checked for 200, read the body with getString(), and closed with end(). That is a full read from the web. 🎉

Perguntas Frequentes

A aula “Obtenha dados de uma API com GET” é grátis?

Sim — o texto completo de “Obtenha dados de uma API com GET” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Arduino & IoT Academy, atualize para CoddyKit PRO. O curso de Arduino & IoT Academy inclui 4 aulas no total.

O que vou aprender em “Obtenha dados de uma API com GET”?

Faça uma solicitação HTTP e leia a resposta. Você pratica Arduino & IoT Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Arduino & IoT Academy?

Nenhuma experiência prévia é necessária. Arduino & IoT Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “Obtenha dados de uma API com GET”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Arduino & IoT Academy?

Sim. Cada aula de Arduino & IoT Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Obtenha dados de uma API com GET
  2. Envie leituras dos sensores com POST
  3. Analise respostas JSON
  4. Use HTTPS com segurança
← Voltar para Arduino & IoT Academy