# Example

Let's see a full example of a simple API that combines everything that we described during the documentation! We will first look at the zum.toml config file, and then we will see how to interact with every endpoint defined there using the console!

# The Config File

Our zum.toml file will look like this:

[metadata]
server = "http://localhost:8000"

# zum get-album 8
[endpoints.get-album]
route = "/albums/{id}"
method = "get"
params = ["id"]

# zum search-song 8 saucy
[endpoints.search-song]
route = "/albums/{id}/songs?query={query}"
method = "get"
params = ["id", "query"]

# zum create-album "Bearer super-secret-token" "Greatest Hits" "La Rosalia"
[endpoints.create-album]
route = "/albums"
method = "post"
headers = ["Authorization"]
body = ["name", "artist"]

# zum create-song 8 "Bearer super-secret-token" "Con Altura" 161
[endpoints.create-song]
route = "/albums/{id}/songs"
method = "post"
params = ["id"]
headers = ["Authorization"]
body = [
    "name",
    { name = "duration", type = "integer" }
]

# Interacting with the API

Now, let's interact with our endpoints:

  • Get the album with id 8:

    zum get-album 8
    
  • Get all the songs inside that album with id 8 with the string "saucy" on their names:

    zum search-song 8 saucy
    
  • Create an album named "Greatest Hits" by the artist "La Rosalia" (authorization-restricted action):

    zum create-album "Bearer super-secret-token" "Greatest Hits" "La Rosalia"
    
  • Create a song named "Con Altura" that lasts for 161 seconds inside the album with id 8 (authorization-restricted action):

    zum create-song 8 "Bearer super-secret-token" "Con Altura" 161