API Integration for AI Coders | SheCodes
Intermediate 6 min read

API Integration for AI Coders

APIs let your app talk to the rest of the internet: pulling in weather, showing user profiles, processing payments, and more. Here's what you need to know.

What is an API?

Think of it like ordering at a restaurant

You (your app) tell the waiter (the API) what you want. The waiter goes to the kitchen (another company's computer) and brings back your food (the data). You never go into the kitchen yourself. The waiter handles it all.

Real-world examples

  • 🌤️ A weather widget on your site pulls today's forecast from a weather service
  • 💳 Your checkout page asks Stripe to process a credit card payment
  • 📍 A store locator shows nearby locations using Google Maps data
  • 🔐 Your login page checks credentials through an authentication service

The 4 Things You Can Do With Data

Every app that works with data does some combination of these four actions. When you hear developers say "CRUD", this is what they mean.

📖 Get

Read or fetch data

Show a list of blog posts

✏️ Create

Add new data

Submit a new comment

🔄 Update

Change existing data

Edit your profile name

🗑️ Delete

Remove data

Delete a photo

Two Ways Data Shows Up in Your App

You don't need to understand the code behind these. Just know which approach to ask your AI tool for.

Pre-loaded data Faster The data is fetched before the page appears. The visitor sees everything immediately, no loading spinner. Best for:
  • Blog posts, product listings, profile pages
  • Data that doesn't change every second
  • Pages that need to show up well in Google
What to tell your AI tool:

“Fetch the data on the server side so the page loads with everything already visible.”

Live-loaded data Interactive The page loads first, then the data arrives a moment later. The visitor sees a brief loading state. Best for:
  • Search results, filters, live dashboards
  • Data that updates based on what the user clicks
  • Real-time features like chat or notifications
What to tell your AI tool:

“Fetch the data on the client side with a loading spinner while it loads.”

What Can Go Wrong (and How to Handle It)

When your app asks for outside data, three things can happen. A good app handles all three gracefully.

Still loading... The data hasn't arrived yet. Show something to let people know it's on the way: a spinner, a pulsing placeholder, or a "Loading..." message.
Ask your AI tool for:

“Add skeleton loading placeholders while the data is being fetched.”

It worked! The data arrived successfully. Display it in cards, lists, tables, or whatever layout fits your design.
Ask your AI tool for:

“Display the results in a responsive card grid with the name, image, and description.”

Something broke The request failed. Maybe the service is down or the internet hiccupped. Show a friendly message and a "Try Again" button.
Ask your AI tool for:

“Add an error state with a friendly message and a retry button.”

What's an API Key?

Some APIs are open to anyone (like the free ones listed below). Others require an API key: a special password that identifies your app. It's like a library card: you need one to borrow books, and the library tracks who borrows what.

🔓 No key needed Free public APIs for practice. Anyone can use them.
🔑 Free key required Sign up for a free account to get your key. Usually has usage limits.
💳 Paid key You pay based on how much you use. For serious production apps.

Free APIs to Practice With

These services let anyone pull data for free. Most need no sign-up or API key at all. Perfect for learning.

JSONPlaceholder jsonplaceholder.typicode.com Fake user profiles, blog posts, and comments. The best place to start practicing. Start Here
PokéAPI pokeapi.co Data on every Pokémon: names, types, stats, and images. Fun for building a visual directory. Fun
Open-Meteo open-meteo.com Real weather data for any location: temperature, wind, rain, and forecasts. Practical
REST Countries restcountries.com Info on every country: flags, populations, capitals, currencies, and languages. Needs a free account and API key (sent with each request). Free Key
Dog CEO dog.ceo/dog-api Random dog photos sorted by breed. Great for practicing with images. Images
The Cat API thecatapi.com Random cat photos and breed info. Same idea as Dog CEO, but for cat people. Images

Prompts to Give Your AI Tool

Copy-paste these into Claude Code, Cursor, Bolt, or whichever AI tool you use. Replace the parts in [brackets] with your details.

Show data from an API

“Fetch data from [API URL] and display it in a nice card grid. Show a loading animation while it's fetching, a friendly error message if it fails with a retry button, and a message if there are no results.”

Add a search feature

“Add a search bar that filters results from [API URL] as the user types. Show a loading spinner while searching, highlight the matching text in results, and show 'No results found' when nothing matches.”

Build a weather widget

“Build a weather widget using the Open-Meteo API. Show the current temperature, weather condition with an icon, today's high and low, and a 7-day forecast in a row of small cards. Let the user type a city name to search.”

Create a contact form that saves data

“Create a contact form with name, email, and message fields. When submitted, save the data to [your database or service]. Show a success message after sending and validation errors if fields are empty.”

Display a list with pagination

“Fetch a list of [items] from [API URL] and show 10 at a time. Add a 'Load More' button at the bottom that fetches the next batch. Show how many total items there are and a loading indicator when fetching more.”

Show data from my own database

“Create a page that reads [data type] from my database and displays it in a table. Include sorting by each column, and a way to delete individual rows with a confirmation dialog.”

Real World Example: Weather Dashboard

Imagine you're building a weather app. When a user searches for a city, your app calls a weather API, shows the current temperature and conditions, and displays a 5-day forecast. You need to handle loading (while the API responds), errors (city not found), and display the data in a clean card layout.

Build this with AI

“Build a weather dashboard that lets users search for a city. Use the OpenWeatherMap API (free tier). Show current temperature, weather condition with an icon, humidity, and wind speed in a card. Below it, show a 5-day forecast as small cards. Handle 3 states: loading (show a skeleton), error (show 'City not found'), and success. Use environment variables for the API key. Style with Tailwind CSS.”

Prompt This

Copy-paste these prompts into your AI tool to apply what you just learned.

CONNECT TO AN API

“Connect my app to the [API name] API. I need to [describe what you want to do]. Show me how to make the API call and display the data.”

ADD ERROR HANDLING TO API CALLS

“Add error handling to my API calls. Show loading spinners while fetching, error messages when requests fail, and retry buttons.”

Common Questions

Do I need to know how to code to use APIs?

No! Your AI tool writes the code for you. You just need to know what you want ('show weather data on my homepage') and the AI handles the technical parts.

Is it free to use APIs?

Many APIs are free (like the ones listed above). Others are free up to a certain amount of use, then charge after that. Always check the pricing page before building something that will get lots of traffic.

What if the API I'm using goes down?

That's why error handling matters! Ask your AI tool to 'add error handling with a friendly message and retry button.' Your app should show a nice message instead of breaking.

Can I create my own API?

Yes! If you're using Next.js, your AI tool can create API endpoints right inside your project. Just say 'create an API route that [does whatever you need].' This is useful when you want your app to do something on the server, like save data or talk to a third-party service securely.