Home > Web Front-end > JS Tutorial > Injee - The no configuration instant database for frontend developers.

Injee - The no configuration instant database for frontend developers.

王林
Release: 2024-07-30 13:12:41
Original
396 people have browsed it

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
Copy after login

Use Injee

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

$ java -jar injee-0.2.0.jar
Copy after login

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
Copy after login

Output should be

{
  "health": "ok"
}
Copy after login

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

Copy after login

Output

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

Copy after login

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

Copy after login

Output

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

Copy after login
Copy after login

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

Copy after login
Copy after login
Copy after login

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

Copy after login

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

Copy after login

Output

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

Copy after login
Copy after login

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

Copy after login

Output

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

Copy after login

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

Copy after login
Copy after login
Copy after login

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

Copy after login

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

Copy after login

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

Copy after login
Copy after login
Copy after login

Output

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


Copy after login

Listing Tables

Now let's create a user:

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

Copy after login

Output

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

Copy after login

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

Copy after login

Output

[
  "books",
  "users"
]

Copy after login

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

Copy after login

Let's now fetch all users and confirm our addition

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

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

Copy after login

Now let's search for a string in users:

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

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

Copy after login

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

Copy after login

Output

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

Copy after login

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

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

Copy after login

Output

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

Copy after login

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

The above is the detailed content of Injee - The no configuration instant database for frontend developers.. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template