Quick Start
This document will walk you through the process of using yurl and explore its various features.
We will use the JSONPlaceholder API as an example, which is publically available, so you can follow along with the examples on your own.
Basic
Let's start with the most basic example.
Create a http.yaml
file with the following content:
http.yaml | |
---|---|
We define a single request named ListTodos
which will list all the todos from the JSONPlaceholder API.
Now, let's run the following command:
yurl
by default detects the http.yaml
file and executes the ListTodos
request.
Request with user input
Now we define a request to fetch a single todo by its id. We will define the id
parameter as a variable.
http.yaml | |
---|---|
We define a single request named GetTodo
which will fetch a single todo by its id. We use variables to get the id
from the user.
Learn more about variables here.
Verbose Mode
You can run the requests in verbose mode by passing the -v
flag.
List Requests
We can list all the requests defined in the http.yaml
file by running yurl ls
command.
Post Request with JSON Body
Let's define a request to create a new todo. We will use the POST
method and pass a JSON body as the payload.
http.yaml | |
---|---|
jsonBody
automatically sets the Content-Type
header to application/json
.
Enforcing types on user input variables
We can enforce types on user input variables by specifying the type following the format <varname:type>
.
http.yaml | |
---|---|
Type of variable is displayed in the prompt.
If the user enters a value of a different type, the request will fail.