Practice Designing a Public API
In this lesson, you will learn practice designing a public API. This mimics real-world software development where you define how you expect users to interact with your library before you build it.
Resources
The following resources provide more information for this lesson:
- How to Design a Good API and Why It Matters — Joshua Bloch
Transcript
[0:00] [0: 00] When you're designing a public API, especially a library, you really want to think about the end user. Let's take a look at an example that most of you might be familiar with.
[0:08] [0: 08] This is a TypeScript snippet I have here inspired by Jest. I'm importing a function. The API here is essentially this test function, which takes a string and a callback function, and then it has an assertion.
[0:21] [0: 22] Now, for a second, let's break this down. That's the API that they designed that now feels intuitive and easy to work with. That's what I want you to be thinking about as you go through this tutorial.
[0:34] [0: 34] To wrap this video, I want to give you a challenge. I want you to come up with five API designs for a points counter that an end user would display in a UI like this.
[0:43] [0: 44] This is on the Next.js Doc's site you see right here, they have these points. I want you to think about an API, a library that an end user might use to design this. Something like this, where useScore is imported from a library. Set a two-minute timer, work on that, and then come back to the video to see my solutions.
[1:02] [1: 03] Great. Welcome back. I hope you enjoyed the challenge. Here are the ones that I came up with. I'm not going to go through all of them. Hope you enjoyed that. Again, keep that in mind throughout this series.