Injee works on GNU/Linux (Debian and Arch flavors), Mac and WSL (Windows Subsystem for Linux). To run injee, in your terminal execute:
To stop injee, in the terminal where you have run, press Ctrl and C at the same time.
Use Injee
When injee is running you can do the stuff mentioned below:
Health
Let’s check if the server is running. We use the API GET http://localhost:4125/ops/health.
In your terminal try:
Output should be
Create books
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:
Output
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:
Output
And it works!
List all books
Now to list all books we use GET http://localhost:4125/api/books:
Output
We get a nice array of books we have stored.
Fetch a book
Now let’s fetch just one book, for that we use the API GET http://localhost:4125/api/books/:id:
Output
So if I prepend idGET http://localhost:4125/api/books/ I get the details of a single book.
Update a book
To updatea book use PUT along with http://localhost:4125/api/books/:id, followed by parameters for the book:
Output
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:
Output
to confirm our update.
Delete a book
Now let’s delete a book. For that use DELETE along with http://localhost:4125/api/books/:id:
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:
Output
Listing Tables
Now let’s create a user:
Output
So now there must be two tables in our db namely books and users, let’s list them using the following API:
Output
Searching Records
Let’s add another user record into users table:
Let’s now fetch all users and confirm our addition
Now let’s search for a string in users:
Ordering Records
Let’s list all the users.
Output
Let’s now order them by name in ascending
Output
Let’s now order them by name in descending
Output
Pagination
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:
Now let’s paginate. Let set per-pageto 2 and page to 2, and see what we get:
Output
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.
File uploads and downlods
Injee offers file store, to upload a file execute these commands:
Output
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:
The file will b stored in the specified path as mentioned above.
Backing Up Injee
Now let’s backup our DB into a file named backup.json:
Output
Stopping Injee
Finally, to stop injee, in terminal where injee is running hit Ctrl+c in terminal where injee is running to stop it.
Loading Backup
Let’s start injee again:
Output
So you have got your original DB back and running. Congrats.
Remove columns
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:
Once the server is running, let’s add some users:
Now let’s list all users:
We get the following output:
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.
We get a message saying that the column has been added. Now let’s list users again:
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:
We get message as shown below that says country column is removed:
Now let’s list users
Now country column is gone as you see below.
In the terminal, where injee is running, you may press Ctrl+C to exit.
Delete Table
Let’s start this tutorial afresh. Hit Ctrl+C to exit to stop injee. Let’s start our injee again:
Now let’s create a user:
So we get a confirmation of the creation:
Now let’s create a book:
As we see below it’s created successfully:
Let’s list tables:
As we see below there are two tables, users and books:
Now let’s delete the table users:
We get a message as shown below, informing us that the table has been deleted:
Now let’s list tables:
As you can see below, we don’t see users table anymore.
In the terminal where injee is started, hit CTRL+C to stop it.