DEV Community

Precious Afolabi
Precious Afolabi

Posted on

Week 10: Working with APIs and Starting to Build

Working with APIs

Week 10 was about working with APIs using the Fetch API. Also started building a weather CLI project, though exam week meant I didn't finish it.

Learning Fetch API

Learned how to make different types of API requests. GET requests to fetch data, POST requests to send data, handling JSON responses, and structuring API calls properly.
Practiced with public APIs like JSONPlaceholder to understand how real API interactions work. Fetching users, posts, creating new posts, updating existing ones.

Error Handling with Fetch

Understanding how fetch handles errors changed how I approach async operations.

Fetch doesn't throw errors for failed HTTP requests. A 404 or 500 status is still a resolved promise. The fetch succeeded in making the request and getting a response, even if that response says "not found" or "server error".

You have to check response.ok or response.status manually. Response.ok is true for status codes 200-299. Anything else means something went wrong.
But that's just HTTP errors.

There's also network failures when the request can't be made at all. Invalid JSON when the response isn't valid JSON. Missing data when the response structure isn't what you expect.

Each type of error needs different handling. Network failures get caught by try/catch. HTTP errors need manual checking. Invalid JSON throws when you call response.json(). Missing data needs validation after parsing.

Building a Weather CLI

Started building a weather CLI that fetches current weather data from OpenWeather API.
Got the basic structure working and started implementing the main functions. Making the API request with city parameters, checking if the response is valid, parsing the weather data, displaying temperature and conditions.
Exam week meant I couldn't finish everything planned, but the core functionality is there.

What This Week Taught Me

There's a difference between learning concepts and applying them. Understanding async/await from last week was one thing. Using it to fetch real data from APIs, handle errors properly, and build something functional is different.

APIs are how backend systems communicate. Everything connects through HTTP requests and JSON responses. This is what backend development actually is.

Moving Forward

Going into Node.js fundamentals. Learning how to build actual backend servers, handle routes, work with the file system, and create real applications.

Question: What tripped you up when you first worked with APIs?

Top comments (0)