Heim > Web-Frontend > js-Tutorial > Injee – Die konfigurationsfreie Sofortdatenbank für Frontend-Entwickler.

Injee – Die konfigurationsfreie Sofortdatenbank für Frontend-Entwickler.

王林
Freigeben: 2024-07-30 13:12:41
Original
395 Leute haben es durchsucht

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
Nach dem Login kopieren

Use Injee

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

$ java -jar injee-0.2.0.jar
Nach dem Login kopieren

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
Nach dem Login kopieren

Output should be

{
  "health": "ok"
}
Nach dem Login kopieren

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

Nach dem Login kopieren

Output

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

Nach dem Login kopieren

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

Nach dem Login kopieren

Output

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

Nach dem Login kopieren
Nach dem Login kopieren

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

Nach dem Login kopieren
Nach dem Login kopieren
Nach dem Login kopieren

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

Nach dem Login kopieren

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

Nach dem Login kopieren

Output

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

Nach dem Login kopieren
Nach dem Login kopieren

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

Nach dem Login kopieren

Output

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

Nach dem Login kopieren

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

Nach dem Login kopieren
Nach dem Login kopieren
Nach dem Login kopieren

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

Nach dem Login kopieren

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

Nach dem Login kopieren

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

Nach dem Login kopieren
Nach dem Login kopieren
Nach dem Login kopieren

Output

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


Nach dem Login kopieren

Listing Tables

Now let's create a user:

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

Nach dem Login kopieren

Output

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

Nach dem Login kopieren

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

Nach dem Login kopieren

Output

[
  "books",
  "users"
]

Nach dem Login kopieren

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

Nach dem Login kopieren

Let's now fetch all users and confirm our addition

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

Nach dem Login kopieren
[
  {
    "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"
  }
]

Nach dem Login kopieren

Now let's search for a string in users:

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

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

Nach dem Login kopieren

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

Nach dem Login kopieren

Output

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

Nach dem Login kopieren

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

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

Nach dem Login kopieren

Output

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

Nach dem Login kopieren

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

Das obige ist der detaillierte Inhalt vonInjee – Die konfigurationsfreie Sofortdatenbank für Frontend-Entwickler.. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Quelle:dev.to
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage