Quick start
This tutorial takes about five minutes. You will create a workspace, send its example request, write your own request, keep its base URL in an environment and check the response with a test.
1. Create a workspace
A workspace is a folder on your disk: its subfolders are collections and every .postino file in it is a request.
- Start Postino. The first time, it opens the welcome tab: click New workspace… under Start.
- Type a name, for example
my-api. The dialog shows where the folder will be created, inside your Documents folder by default. Change… picks another place. Press Create. - Postino creates the folder with an example request,
hello.postino, and alocalenvironment, closes the welcome tab, opens the request in a tab and selects the environment. It remembers the workspace and opens it again the next time you start the app.
You can also choose New workspace… in the workspace switcher next to the Postino name at the top left of the title bar, which is where to find it once the welcome tab is gone. To use a folder you already have, for example a folder inside the repository of your API so the requests travel with the code, click Open folder… in the welcome tab or the workspace switcher instead, or press Ctrl O (⌘ O on macOS).
2. Send the example
Click Send or press Ctrl Enter (⌘ Enter on macOS). The URL, {{baseUrl}}/hello.json, uses the baseUrl variable of the local environment. The response pane shows the status, the time and the size, then the body. Switch between Pretty and Raw, look at the Headers tab, and open the Tests tab: the example checks the response with two tests, and both pass.
3. Create a request
- In the sidebar header, click the New request button. To create it inside a folder, right click the folder and choose New request.
- Type a name, for example
list-users, and press Create. Postino writeslist-users.postinointo the folder and opens it in a tab. - A new request starts as
GET https://example.com. Replace the URL with an API you can reach, for examplehttps://httpbin.org/get, and send it.
The tab shows a dot when it has unsaved changes. Press Ctrl S to save. Send always uses what is in the editor, saved or not.
Closing a request tab discards its unsaved changes without asking. Save first with Ctrl S.
4. Add a variable
Hard coding the host in every request makes it painful to switch between local, staging and production. Move it into a variable of the environment.
- Click Environments in the activity rail on the left (the second icon) and then
local. The environment opens in a tab, with thebaseUrlvariable of the example. - Click Add variable, name it
httpbinand set its value tohttps://httpbin.org. Save with Ctrl S. - Back in your request, change the URL to
{{httpbin}}/get. The variable turns into a chip. An unknown variable shows in red, and clicking it takes you to the active environment to define it.
To add another environment, such as staging, click New environment in the Environments panel, and switch between them with the environment pill at the top right of the title bar or with Ctrl 1, Ctrl 2, and so on.
Your workspace now looks like this:
my-api/ ├── environments/ │ └── local.env ├── .gitignore ├── hello.postino └── list-users.postino
5. Add a test
Open the Post-response tab of the request and write:
test("status is 200", () => {
expect(res.status).toBe(200);
});
test("the response echoes the URL", () => {
expect(res.json().url).toContain("/get");
});Send again. The Tests tab of the response shows 2/2 and the result of each test. A failed test does not stop the others.
6. Look at the file
Open list-users.postino in any text editor. It is short and readable:
GET {{httpbin}}/get
::: post
test("status is 200", () => {
expect(res.status).toBe(200);
});
test("the response echoes the URL", () => {
expect(res.json().url).toContain("/get");
});Commit it with the rest of your code. The .gitignore of the new workspace already holds this line, so .local.env files, where secrets go, never reach git. Add it to your own .gitignore when you open an existing folder:
*.local.env