From the course: Planning a Versioned RESTful API with Claude
Initial endpoints design - Claude Tutorial
From the course: Planning a Versioned RESTful API with Claude
Initial endpoints design
- [Instructor] Alright, now that we have a project and our knowledge base, we are ready to start working with Claude to help us design our API. Now, the first API that we are going to design is to create the book. I already have a prompt that I'm pasting here, and we are asking Claude to create the RESTful API spec for creating the book. And this should include the models for creating the book, the success response model and error response model. We also ask it to create the Markdown artifact. And when the artifact is created, you can download that artifact or you can add it to your knowledge base. I tend to download the artifact so that I can use it outside of Claude in other systems where this could be useful. And I have selected the chat response to be explanatory. Now, before I do that, I would also like to show you one thing which is this schema. So when the book is created for the first time, it has a status and the default status is pending. It's because when publishers, they send their books, they need to review to make sure everything is fine before they can finalize and when the book becomes active. This is important when we are working on creating the API, because when the publisher are going to send the POST request, we want the status to be pending by default. Now, I'm going to close that. And with this I'm going to send the prompt. And within a few moments Claude will start responding. And as we ask for the Markdown artifact, it is creating the artifact. This card is indication of that. And it is continuing to do its work. So we'll wait for a few moments before we can start validating the outcome that we have received from Claude. Great. So now it has completed the artifact. On the left, it is just summarizing the things it has done. I'm going to scroll up, and we can review what outcome we have received. So it starts with overview. Then it defines the endpoint, it defines the HTTP method, which is POST. It says that the authentication of JWT token is required. This is the request model. And within the request what are the headers that are needed and the request body schema. And this is the example of how the request would be sent. And for the success response, the status code is 201, created. The headers will have the content type and location and the success response schema where you get the success message data. And as you can see, the status is pending. So this is the enum as we were talking, that once the book is created in the system, it is in pending state. So it got it correctly. And then the example of a success response with status pending. And then what if the error occurs. If it is from the client giving us the incorrect data, it is 400, bad request. The authentication, if the header doesn't have the authentication header, if the server has a problem, we'll get HTTP 500 error, and some notes on rate limiting, which are based on the best practices. So as you can see, with a directed prompt specific for one request that you are working with and with access to knowledge base, you can really generate high-quality Markdown artifacts using Claude. So as you can imagine, once you have the access to knowledge base and you provide that to Claude and ask a very specific question in your chat, you can get high-quality Markdown artifact that you can hand over to developers or use it in external systems. So now that the Markdown artifact is ready, one thing that you can do is either take it by downloading it to other systems, which is my preference. I'm going to download this file and save it. And that's it. So now we have created our first artifact, which is about creating the book. Let's go back to the project and see that our thread is here. Now we are going to create another artifact, and that is all about publishing the book. So I'm going to past the prompt here. And now we are saying we want RESTful API spec for finalizing the book, which means that it changes the status from pending to active. And we are specifically asking Claude to create the Markdown artifact. And I'm going to hit Send. I'm going to leave the choice of responses explanatory for now. And like before, we should start seeing the Markdown artifact being created by Claude, but for this specific purpose. So overview, as I scroll up, it's only about changing the status and creating this one endpoint, which is called Finalize on Book ID. It tells that you need to provide the path parameter, request headers. There is no request body because all you're doing is changing the status. The success response is 200, okay, well, how the response body would look like, how the error responses would look like, and all of that information as before. Now, it also provides, with some business rules, rate limiting, security consideration. And this is because in our project instruction we said that you act as an API architect. You already have experience in creating the books' APIs. So it is giving general guidelines on best practices on when developers start implementing this API, what things they should keep in mind. It also provides us with the example usage, which is great. So now that we have the second artifact ready, I'm going to download it again. So we have two artifacts now. So now that we have finalized the book, we finally need an API endpoint for creating the book so that publishers can verify the information stored in BookHub's databases. So I am going to go back to the projects and I'm going to paste the third prompt, which is all about getting all and single book for a logged-in publisher. And we also need to create the Markdown artifact similar to past two chats. Now, the great point here is once you're in the context of a project, you can focus on one thread with one problem in mind and generate artifacts and start downloading the artifacts. So this is the third artifact for getting the book from BookHub's ecosystem. And as you can see, it started creating the Markdown artifact. It talks about the authentication token, the base URL, and the endpoint for getting all the books would be HTTP GET with books endpoint, which is plural, a collection resource. Authentication required is yes, and what query parameters a caller can pass in. It has taken the pagination concept, which is the page number and the limits of how many records to send, the filtering by status, by pending active or inactive, and the sorting and ordering by those sort fields. So if the response is successful, this is what the structure would look like. If the error responses are there, it could be 401, 403, 500, which is internal server error. And if you're asking for a single book, it is HTTP GET books/specific book ID. It also requires authentication. And again, now, instead of getting the array of books, which are paginated, you're getting one single book here and the error responses. So every single time it has provided us with the best practices on rate limiting and how to implement those endpoints, which is a great thing that you can hand over to developers. So now that we have the third artifact, I'm going to download that as well. So now we have three artifacts. If I go back to the project, we have three chats and three artifacts. So this is how you can do your initial endpoint design and start saving the responses in your local folder so that you can reuse them later in your other ecosystems, such as if you're creating issues in GitHub issues or you're using Atlassian Jira, you can start pasting or upload these documents for helping your developers implement the system.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.