👩💻Using your project
Learn how to make API requests to query your project's data
Last updated
Learn how to make API requests to query your project's data
Last updated
Now that we've deployed our project, and created an API key to authenticate ourselves, let's use our API and create some data.
Although we don't have any data at the moment, let's list our galaxies to make sure everything is working as expected. Let's make a GET
request to do so. You can use any HTTP client to do so, like curl, or Postman.
If everything is working well, you should get an empty array in response:
Let's do the same thing for planets:
You should see the same result.
Let's make a POST
request to create our first galaxy.
This should return a galaxy with an auto-generated id
and a name set to "Milky Way", like this:
You can try to run the first request to see that our galaxy is now present in the list of galaxies.
We can also create a Planet; let's create planet Earth:
You should get a result with an automatically generated ID, which should look something like this:
Now, let's say we want to create planet Neptune in our model, and have it be linked to the Milky Way galaxy we created just before. When we defined our Planet model, we added a property called galaxy
, which represents a related Galaxy entity (using the the reference
keyword).
This allows us to link a Planet to a Galaxy, directly upon creation. By re-using the Galaxy id we obtained when we created the Milky Way, we can write the following request to create planet Neptune:
The result should look something like this, with an automically generated id
and a galaxyId
set to the galaxy's id we passed as input.
Our API seems to work well, the last thing we can do is make some updates to our data model or API if we need to.