DEV Community

Cover image for Injee - The no configuration instant database for frontend developers.
Karthikeyan A K
Karthikeyan A K

Posted on

Injee - The no configuration instant database for frontend developers.

As a front end developer it's a pain to wait for API's to be delivered. What if there is a miracle Database that has the API built in. Well, it's no longer fantasy anymore. Injee is a Database that comes with ready to use CRUD API's for front end developers. By reading this page, you will learn how to use Injee, create a record of books in injee, and you will learn how to manipulate and search the data.

Getting Started

Install Java

You need to do this only once. Visit https://java.com to download Java for your machine. Once installed on your CMD, or Terminal type java --varsion and it must work.

Download Injee

You can download injee by clicking here. Or in your terminal use:

$ wget https://codeberg.org/injee/injee/releases/download/0.2.0/injee-0.2.0.jar
Enter fullscreen mode Exit fullscreen mode

Use Injee

Navigate to the directory where the injee jar file is downloaded, and run it using:

$ java -jar injee-0.2.0.jar
Enter fullscreen mode Exit fullscreen mode

Health

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
Enter fullscreen mode Exit fullscreen mode

Output should be

{
  "health": "ok"
}
Enter fullscreen mode Exit fullscreen mode

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:


$ curl -X POST http://localhost:4125/api/books \
       -H "Content-Type: application/json" \
       -d '{"title": "Treasure Island", "author": "Robert Louis Stevenson"}'

Enter fullscreen mode Exit fullscreen mode

Output


{
  "title": "Treasure Island",
  "author": "Robert Louis Stevenson",
  "id": "722e2b57-59cc-4254-85b5-562858264f75"
}

Enter fullscreen mode Exit fullscreen mode

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"}'

Enter fullscreen mode Exit fullscreen mode

Output


{
  "title": "Adventures of Huckleberry Finn",
  "author": "Mark Twain",
  "id": "689976e3-082e-4943-9525-a21b47cba325"
}

Enter fullscreen mode Exit fullscreen mode

And it works!

List all books

Now to list all books we use GET http://localhost:4125/api/books:


$ curl -X GET http://localhost:4125/api/books

Enter fullscreen mode Exit fullscreen mode

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"
  }
]

Enter fullscreen mode Exit fullscreen mode

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:


$ curl -X GET http://localhost:4125/api/books/689976e3-082e-4943-9525-a21b47cba325

Enter fullscreen mode Exit fullscreen mode

Output


{
  "title": "Adventures of Huckleberry Finn",
  "author": "Mark Twain",
  "id": "689976e3-082e-4943-9525-a21b47cba325"
}

Enter fullscreen mode Exit fullscreen mode

So if I prepend id GET 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:


$ curl -X PUT http://localhost:4125/api/books/689976e3-082e-4943-9525-a21b47cba325 \
       -H "Content-Type: application/json" \
       -d '{"title": "Adventures of Tom Sawyer"}'

Enter fullscreen mode Exit fullscreen mode

Output


{
  "title": "Adventures of Tom Sawyer",
  "author": "Mark Twain",
  "id": "689976e3-082e-4943-9525-a21b47cba325"
}

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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"
  }
]

Enter fullscreen mode Exit fullscreen mode

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:


$ curl -X DELETE http://localhost:4125/api/books/689976e3-082e-4943-9525-a21b47cba325

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Output


[
  {
    "title": "Treasure Island",
    "author": "Robert Louis Stevenson",
    "id": "722e2b57-59cc-4254-85b5-562858264f75"
  }
]


Enter fullscreen mode Exit fullscreen mode

Listing Tables

Now let's create a user:


$ curl -X POST http://localhost:4125/api/users \
       -H "Content-Type: application/json" \
       -d '{"name": "Karthik"}'

Enter fullscreen mode Exit fullscreen mode

Output


{
  "name": "Karthik",
  "created_at": "2024-07-22T11:18:42Z",
  "updated_at": "2024-07-22T11:18:42Z",
  "id": "ad100ab0-7893-421d-9233-353cc8899aa9"
}

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Output


[
  "books",
  "users"
]

Enter fullscreen mode Exit fullscreen mode

Searching Records

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"}'

Enter fullscreen mode Exit fullscreen mode

Let's now fetch all users and confirm our addition


$ curl -X GET http://localhost:4125/api/users

Enter fullscreen mode Exit fullscreen mode

[
  {
    "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"
  }
]

Enter fullscreen mode Exit fullscreen mode

Now let's search for a string in users:


$ curl -X GET http://localhost:4125/api/users?q=Pari

Enter fullscreen mode Exit fullscreen mode

[
  {
    "name": "Pari",
    "created_at": "2024-07-22T11:23:27Z",
    "updated_at": "2024-07-22T11:23:27Z",
    "id": "1f06bb65-1f2d-4980-9cfc-cf3d38c9db7e"
  }
]

Enter fullscreen mode Exit fullscreen mode

Backing Up Injee

Now lets backup our DB into a file named backup.json:


$ curl -X GET http://localhost:4125/ops/save?file=backup.json

Enter fullscreen mode Exit fullscreen mode

Output


{
  "message": "saved to file backup.json"
}

Enter fullscreen mode Exit fullscreen mode

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:


$ java -jar injee-0.2.0.jar

Enter fullscreen mode Exit fullscreen mode

$ curl -X GET http://localhost:4125/ops/load?file=backup.json

Enter fullscreen mode Exit fullscreen mode

Output


{
  "message": "loaded from file backup.json"
}

Enter fullscreen mode Exit fullscreen mode

So you have got your original DB back and running. Congrats.

Keep up to date

One of the best ways to keep upto date with Injee is to follow its page here https://injee.codeberg.page/ , or follow its RSS here https://codeberg.org/injee.rss

Top comments (1)

Collapse
 
richardevcom profile image
richardevcom

Injee is an in memory database, that is if you stop it all data will be gone. So do backup the data if you want to load it the next time you start injee.

You forgot to mention a very crucial point in this post.