In the previous guide, we covered how to set up your database tables and add data to them. This time, we'll dive into understanding how your API interacts with your database.
Think of your database as a filing cabinet that holds all the data and information for your application. The API acts as an office clerk, processing requests and managing the flow of data between your database and the outside world.
Whenever you need to retrieve data from the database, you have to go through the API. It will handle your request, search the "filing cabinet" for the required data, process it, and relay it back to you in an understandable format.
To access the API page in Xano, you can either click the "API" link in the top navigation bar or use the left sidebar menu. Once there, you'll see an "API group" called "public." Click "Explore" to find all the CRUD (Create, Read, Update, Delete) API endpoints generated for each of your database tables during the Jumpstart process.
Xano also provides a handy link to the auto-generated documentation in Swagger, making it easy to understand and work with your API endpoints.
Let's explore the anatomy of an API endpoint by looking at the "POST" endpoint, which is used to create a new record in the "merchant" database table.
Inputs: These are the pieces of information the API needs to understand and process your request. In this case, the inputs are the "name" and "description" of the merchant.
Function Stack: This is the core logic that defines what your API endpoint does. For the "POST" endpoint, it adds a new record to the "merchant" table.
Response: This is the data you'll receive back from the API after it has processed your request. In our example, the response will be the newly created merchant record.
One of the great features of Xano is the ability to run and test your API endpoints directly within the tool. Click the "Run in Debug" button in the top-right corner to open a new window. Inside the green parentheses, you can provide the required inputs for the API endpoint.
For example, let's test the "POST" endpoint by adding a new merchant:
("High Street Deli", "Deli Sandwiches")
Hit "Run," and you'll see a success message along with the response containing the new merchant record.
Next, let's look at the "GET" endpoint, which queries all the merchant records. Since there are no inputs required, you can simply click "Run" to retrieve all the records from the "merchant" table.
This guide covered the basics of understanding how your API interacts with your database. Be sure to check out the other guides on using the "UPDATE" and "DELETE" endpoints to round out your knowledge of CRUD operations.
In the next guide, we'll explore how to connect Xano to a front-end application, bringing your backend to life!
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free