Injee works on GNU/Linux (Debian and Arch flavors), Mac and WSL (Windows Subsystem for Linux). To run injee, in your terminal execute:
$ curl -L https://yu7.in/run-injee | sh
To stop injee, in the terminal where you have run, press Ctrl
and C
at the same time.
When injee is running you can do the stuff mentioned below:
Let’s check if the server is running. We use the API GET http://localhost:4125/ops/health
.
In your terminal try:
$ curl -X GET http://localhost:4125/ops/health
Output should be
{
"health": "ok"
}
So let’s create a repo of books, magically injee has the API POST http://localhost:4125/api/books
to create a book. If you want to create a repo of cars, injee has the API POST http://localhost:4125/api/cars
API. So let’s create a book and store it in injee:
$ curl -X POST http://localhost:4125/api/books \
-H "Content-Type: application/json" \
-d '{"title": "Treasure Island", "author": "Robert Louis Stevenson"}'
Output
{
"title": "Treasure Island",
"author": "Robert Louis Stevenson",
"id": "722e2b57-59cc-4254-85b5-562858264f75"
}
So injee stores the book, and gives out a JSON that has all the values you sent to injee, as well as a UUID, which is assigned to a ney named id
.
Now let’s create another book:
$ curl -X POST http://localhost:4125/api/books \
-H "Content-Type: application/json" \
-d '{"title": "Adventures of Huckleberry Finn", "author": "Mark Twain"}'
Output
{
"title": "Adventures of Huckleberry Finn",
"author": "Mark Twain",
"id": "689976e3-082e-4943-9525-a21b47cba325"
}
And it works!
Now to list all books we use GET http://localhost:4125/api/books
:
$ curl -X GET http://localhost:4125/api/books
Output
[
{
"title": "Treasure Island",
"author": "Robert Louis Stevenson",
"id": "722e2b57-59cc-4254-85b5-562858264f75"
},
{
"title": "Adventures of Huckleberry Finn",
"author": "Mark Twain",
"id": "689976e3-082e-4943-9525-a21b47cba325"
}
]
We get a nice array of books we have stored.
Now let’s fetch just one book, for that we use the API GET http://localhost:4125/api/books/:id
:
$ curl -X GET http://localhost:4125/api/books/689976e3-082e-4943-9525-a21b47cba325
Output
{
"title": "Adventures of Huckleberry Finn",
"author": "Mark Twain",
"id": "689976e3-082e-4943-9525-a21b47cba325"
}
So if I prepend id
GET http://localhost:4125/api/books/
I get the details of a single book.
To updatea book use PUT
along with http://localhost:4125/api/books/:id
, followed by parameters for the book:
$ curl -X PUT http://localhost:4125/api/books/689976e3-082e-4943-9525-a21b47cba325 \
-H "Content-Type: application/json" \
-d '{"title": "Adventures of Tom Sawyer"}'
Output
{
"title": "Adventures of Tom Sawyer",
"author": "Mark Twain",
"id": "689976e3-082e-4943-9525-a21b47cba325"
}
So as you can see above, the title of the book has been changed from Adventures of Huckleberry Finn
to Adventures of Tom Sawyer
.
Now let’s list all books:
$ curl -X GET http://localhost:4125/api/books
Output
[
{
"title": "Treasure Island",
"author": "Robert Louis Stevenson",
"id": "722e2b57-59cc-4254-85b5-562858264f75"
},
{
"title": "Adventures of Tom Sawyer",
"author": "Mark Twain",
"id": "689976e3-082e-4943-9525-a21b47cba325"
}
]
to confirm our update.
Now let’s delete a book. For that use DELETE
along with http://localhost:4125/api/books/:id
:
$ curl -X DELETE http://localhost:4125/api/books/689976e3-082e-4943-9525-a21b47cba325
Output
There will be no output, you should get status 204
, if you are trying it in code and receive the response object.
Now let’s list all books, and confirm that Adventures of Tom Sawyer
has been deleted:
$ curl -X GET http://localhost:4125/api/books
Output
[
{
"title": "Treasure Island",
"author": "Robert Louis Stevenson",
"id": "722e2b57-59cc-4254-85b5-562858264f75"
}
]
Now let’s create a user:
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Karthik"}'
Output
{
"name": "Karthik",
"created_at": "2024-07-22T11:18:42Z",
"updated_at": "2024-07-22T11:18:42Z",
"id": "ad100ab0-7893-421d-9233-353cc8899aa9"
}
So now there must be two tables in our db namely books
and users
, let’s list them using the following API:
$ curl -X GET http://localhost:4125/ops/tables
Output
[
"books",
"users"
]
Let’s add another user record into users
table:
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Pari"}'
Let’s now fetch all users and confirm our addition
$ curl -X GET http://localhost:4125/api/users
[
{
"name": "Karthik",
"created_at": "2024-07-22T11:18:42Z",
"updated_at": "2024-07-22T11:18:42Z",
"id": "ad100ab0-7893-421d-9233-353cc8899aa9"
},
{
"name": "Pari",
"created_at": "2024-07-22T11:23:27Z",
"updated_at": "2024-07-22T11:23:27Z",
"id": "1f06bb65-1f2d-4980-9cfc-cf3d38c9db7e"
}
]
Now let’s search for a string in users
:
$ curl -X GET http://localhost:4125/api/users?q=Pari
[
{
"name": "Pari",
"created_at": "2024-07-22T11:23:27Z",
"updated_at": "2024-07-22T11:23:27Z",
"id": "1f06bb65-1f2d-4980-9cfc-cf3d38c9db7e"
}
]
Let’s list all the users.
$ curl -X GET http://localhost:4125/api/users
Output
[
{
"name": "Karthik",
"created_at": "2024-10-05T09:16:41Z",
"updated_at": "2024-10-05T09:16:41Z",
"id": "b9a52bcf-a8a6-467f-be85-dae9b50a4393"
},
{
"name": "Pari",
"created_at": "2024-10-05T09:16:51Z",
"updated_at": "2024-10-05T09:16:51Z",
"id": "f79c4c99-16f5-41e6-9edf-a6342364cd5a"
}
]
Let’s now order them by name in ascending
$ curl -X GET http://localhost:4125/api/users?sort=name&order=asc
Output
[
{
"name": "Karthik",
"created_at": "2024-10-05T09:16:41Z",
"updated_at": "2024-10-05T09:16:41Z",
"id": "b9a52bcf-a8a6-467f-be85-dae9b50a4393"
},
{
"name": "Pari",
"created_at": "2024-10-05T09:16:51Z",
"updated_at": "2024-10-05T09:16:51Z",
"id": "f79c4c99-16f5-41e6-9edf-a6342364cd5a"
}
]
Let’s now order them by name in descending
$ curl http://localhost:4125/api/users?sort=name&order=desc
Output
[
{
"name": "Pari",
"created_at": "2024-10-05T09:16:51Z",
"updated_at": "2024-10-05T09:16:51Z",
"id": "f79c4c99-16f5-41e6-9edf-a6342364cd5a"
},
{
"name": "Karthik",
"created_at": "2024-10-05T09:16:41Z",
"updated_at": "2024-10-05T09:16:41Z",
"id": "b9a52bcf-a8a6-467f-be85-dae9b50a4393"
}
]
Close any running instance of injee by hitting Ctrl + C
in your terminal and start it again using curl -L https://yu7.in/run-injee | sh
, this will give a clean slate and fresh Injee DB.
Let’s see how we can paginate in Injee. For that, lets first create five users as shown below:
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Pari"}'
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Kaari"}'
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Oori"}'
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Adiyamaan"}'
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Beghan"}'
Now let’s paginate. Let set per-page
to 2 and page
to 2, and see what we get:
$ curl -X GET http://localhost:4125/api/users?per-page=2&page=2
Output
[
{
"name": "Oori",
"created_at": "2024-10-18T06:13:34Z",
"updated_at": "2024-10-18T06:13:34Z",
"id": "ae9acd31-9958-449a-8127-6d3c4f20b954"
},
{
"name": "Adiyamaan",
"created_at": "2024-10-18T06:13:42Z",
"updated_at": "2024-10-18T06:13:42Z",
"id": "39a1b2c8-2ef8-4bd6-a3a6-7e534968f066"
}
]
When per-page
is not specified, it defaults to 10. If page
is not specified, pagination does not kick in, and injee returns all the records.
Injee offers file store, to upload a file execute these commands:
$ curl -X POST http://localhost:4125/files \
-F "file=@/path/to/file"
Output
{ "id": "bedd2710-2cfe-4a04-9380-d736b50f77c0" }
Once the file is uploaded, you will get a file id
as shown above. Note it down.
To download the file, replace the file-id
with the id
you got from the upload operation before:
$ curl -X GET http://localhost:4125/files/file-id -o /path/to/save/file_name.extension
The file will b stored in the specified path as mentioned above.
Now let’s backup our DB into a file named backup.json
:
$ curl -X GET http://localhost:4125/ops/save?file=backup.json
Output
{
"message": "saved to file backup.json"
}
Finally, to stop injee, in terminal where injee is running hit Ctrl+c
in terminal where injee is running to stop it.
Let’s start injee again:
$ curl -L https://yu7.in/run-injee | sh
$ curl -X GET http://localhost:4125/ops/load?file=backup.json
Output
{
"message": "loaded from file backup.json"
}
So you have got your original DB back and running. Congrats.
Here we will ssee how to remove columns. Let’s start injee afreash. If you are running it, hit Ctrl+C
to exit it, and run:
$ curl -L https://yu7.in/run-injee | sh
Once the server is running, let’s add some users:
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Saravanan"}'
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Karthikeyan"}'
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Aravindan", "country": "Sri Lanka"}'
Now let’s list all users:
$ curl http://localhost:4125/api/users
We get the following output:
[
{
"name": "Saravanan",
"created_at": "2024-08-19T15:23:54Z",
"updated_at": "2024-08-19T15:23:54Z",
"id": "902b155f-3bd5-4309-bfe4-104c49c51fe2"
},
{
"name": "Karthikeyan",
"created_at": "2024-08-19T15:24:09Z",
"updated_at": "2024-08-19T15:24:09Z",
"id": "46f917dd-99c2-45ca-bed2-2906afee16f8"
},
{
"name": "Aravindan",
"country": "Sri Lanka",
"created_at": "2024-08-19T15:24:18Z",
"updated_at": "2024-08-19T15:24:18Z",
"id": "e9b3cd95-861e-414e-9417-c6267b51c222"
}
]
You see that only Aravindan has a country, and others do not. Now let’s add country
column to users
and default it to India.
$ curl -X POST http://localhost:4125/ops/add-column/users/country \
-H "Content-Type: application/json" \
-d '{"default": "India"}'
{
"message": "added column country to table users"
}
We get a message saying that the column has been added. Now let’s list users again:
$ curl http://localhost:4125/api/users
[
{
"name": "Saravanan",
"created_at": "2024-08-19T15:23:54Z",
"updated_at": "2024-08-19T15:23:54Z",
"country": "India",
"updated_at": "2024-08-19T15:27:09Z",
"id": "902b155f-3bd5-4309-bfe4-104c49c51fe2"
},
{
"name": "Karthikeyan",
"created_at": "2024-08-19T15:24:09Z",
"updated_at": "2024-08-19T15:24:09Z",
"country": "India",
"updated_at": "2024-08-19T15:27:09Z",
"id": "46f917dd-99c2-45ca-bed2-2906afee16f8"
},
{
"name": "Aravindan",
"country": "Sri Lanka",
"created_at": "2024-08-19T15:24:18Z",
"updated_at": "2024-08-19T15:24:18Z",
"id": "e9b3cd95-861e-414e-9417-c6267b51c222"
}
]
You see that country of Aravindan remains untouched, and it’s still Sri Lanka, but for Saravanan and Karthikeyan, country is India, these values have been newly added.
Now let’s remove the country column:
$ curl -X DELETE http://localhost:4125/ops/remove-column/users/country
We get message as shown below that says country column is removed:
{
"message": "removed column country from table users"
}
Now let’s list users
$ curl http://localhost:4125/api/users
Now country column is gone as you see below.
[
{
"name": "Saravanan",
"created_at": "2024-08-19T15:23:54Z",
"updated_at": "2024-08-19T15:23:54Z",
"updated_at": "2024-08-19T15:27:09Z",
"id": "902b155f-3bd5-4309-bfe4-104c49c51fe2"
},
{
"name": "Karthikeyan",
"created_at": "2024-08-19T15:24:09Z",
"updated_at": "2024-08-19T15:24:09Z",
"updated_at": "2024-08-19T15:27:09Z",
"id": "46f917dd-99c2-45ca-bed2-2906afee16f8"
},
{
"name": "Aravindan",
"created_at": "2024-08-19T15:24:18Z",
"updated_at": "2024-08-19T15:24:18Z",
"id": "e9b3cd95-861e-414e-9417-c6267b51c222"
}
]
In the terminal, where injee is running, you may press Ctrl+C
to exit.
Let’s start this tutorial afresh. Hit Ctrl+C
to exit to stop injee. Let’s start our injee again:
$ curl -L https://yu7.in/run-injee | sh
Now let’s create a user:
$ curl -X POST http://localhost:4125/api/users \
-H "Content-Type: application/json" \
-d '{"name": "Aravindan", "country": "Sri Lanka"}'
So we get a confirmation of the creation:
{
"name": "Aravindan",
"country": "Sri Lanka",
"created_at": "2024-08-21T15:04:25Z",
"updated_at": "2024-08-21T15:04:25Z",
"id": "a65cf235-2a0e-4ca2-9114-79fb3722184d"
}
Now let’s create a book:
$ curl -X POST http://localhost:4125/api/books \
-H "Content-Type: application/json" \
-d '{"title": "Adventures of Huckleberry Finn", "author": "Mark Twain"}'
As we see below it’s created successfully:
{
"title": "Adventures of Huckleberry Finn",
"author": "Mark Twain",
"created_at": "2024-08-21T15:04:32Z",
"updated_at": "2024-08-21T15:04:32Z",
"id": "8f0df4e3-bc34-4dd2-a979-39469168bf10"
}
Let’s list tables:
$ curl -X GET http://localhost:4125/ops/tables
As we see below there are two tables, users
and books
:
[
"users",
"books"
]
Now let’s delete the table users
:
$ curl -X DELETE http://localhost:4125/api/delete-table/users
We get a message as shown below, informing us that the table has been deleted:
{
"message": "deleted table users"
}
Now let’s list tables:
$ curl -X GET http://localhost:4125/ops/tables
As you can see below, we don’t see users
table anymore.
[
"books"
]
In the terminal where injee is started, hit CTRL+C
to stop it.