Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/smolthing/backend-vertx

gRPC and HTTP services using vert.x
https://github.com/smolthing/backend-vertx

backend java mysql vertx

Last synced: about 1 month ago
JSON representation

gRPC and HTTP services using vert.x

Awesome Lists containing this project

README

        

# Backend

### Getting Started

```
./gradlew clean run
```

Launch the tests:

```
./gradlew clean test
```

Package your application:

```
./gradlew clean assemble
```

### HTTP API

Go to http://localhost:8000.

#### GET `/ping``

Healthcheck

```
curl -i -H 'accept: application/json' http://localhost:8000/ping
```

Response

```
{
"status": "UP",
"checks": [
{
"id": "App connection",
"status": "UP"
}
],
"outcome": "UP"
}
```

#### GET `/users/:id`

Get user by id

```
curl -i -H 'accept: application/json' http://localhost:8000/users/1
```

Response

```
{
"id": 1,
"name": "smol"
}
```

### gRPC API

Go to http://localhost:9000.

Use protobuf schema from [User.proto](./src/main/proto/User.proto).

```
service UserService {
rpc GetUser (GetUserRequest) returns (GetUserResponse) {}
}

message User {
int64 id = 1;
string name = 2;
}
message GetUserRequest {
int64 id = 1;
}

message GetUserResponse {
User user = 1;
}
```

#### GetUser

GetUserRequest

```
{ "id": 1 }
```

GetUserResponse

```
{
"user": {
"id": "1",
"name": "smol"
}
}
```

### MySQL database

Go to http://localhost:3306.

#### Set up a database using docker.

Run mysql container:

```
docker run --name backend-mysql -d \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=password \
-v mysql:/var/lib/mysql \
mysql:8
```

Create database and table:

```
docker exec -it backend-mysql bash
create database backend;
use backend;

CREATE TABLE IF NOT EXISTS `user` (
`id` BINARY(16) PRIMARY KEY NOT NULL DEFAULT (UUID_TO_BIN(UUID())),
`account_id` BIGINT(20) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`created_at` DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
UNIQUE KEY `unique_name_index` (`account_id`, `name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
INSERT INTO `user` (`account_id`, `name`)VALUES (1, "smol");
```

#### Database Schema

user

| Column | Type | Not Null | Default | Description |
|------------|--------------|----------|-----------------------------------------------|---------------------------------------------------------------------------------|
| id | binary | yes | UUID in binary format | The ID of the user. This is 128-bit UUID stored in 16-bit binary format. |
| account_id | bigint(20) | yes | | The name of the user. This is a string with a maximum length of 255 characters. |
| name | varchar(255) | yes | | The name of the user. This is a string with a maximum length of 255 characters. |
| created_at | datetime | yes | CURRENT_TIMESTAMP | The date and time the user was created. |
| updated_at | datetime | yes | CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | The date and time the user was last updated. |

#### Database migration

[Migrations](./src/main/resources/db/migrations), [Seeds](./src/main/resources/db/seeds)

## Documentation

Part 1. https://dev.to/smolthing/build-web-application-in-vertx-part-1-3jc4[Build web application in
Vert.x]
git log