Cahsper is an alternative of twitter for a solitary person.
Version | Build | Quality | Coverage |
---|---|---|---|
- sbt 1.4.x
- Scala 2.13.x
- JVM 11
- MariaDB 10.x
AWS Cognito
Create AWS Cognito userpool. Cahsper use AWS cognito for authorization/authentication and creates username
from AWS cognito name
attribute.
So, you have to select name
attribute when create userpool and it's must be UNIQUE.
Next, please create App clients
and select Enable sign-in API for server-based authentication (ADMIN_NO_SRP_AUTH)
.
DataBase
Create a database schema. Also, schema name is anything will be fine.
CREATE DATABASE cahsper;
All tables will be migrated after run the cahsper automatically.
Cahsper provide docker image.
Please see more docker-compose.yml
Cahsper backend (API server) read all settings from the system environment variable. You have to set the following system environment variables.
Property | Description | Type | Default | Example |
---|---|---|---|---|
CAHSPER_DB_DATASOURCE_URL |
Data source url for JDBC connection. | string |
- | jdbc:mariadb://127.0.0.1/cahsper?useUnicode=true&characterEncoding=utf8mb4 |
CAHSPER_DB_USER |
Database user name. | string |
- | root |
CAHSPER_DB_PASSWORD |
Database user password. | string |
- | pass |
CAHSPER_DB_CONNECTION_TIMEOUT |
Database connection timeout. | int |
30000 |
30000 |
CAHSPER_DB_MAXIMUM_POOLSIZE |
Connection pool size. | int |
6 |
6 |
Property | Description | Type | Default | Example |
---|---|---|---|---|
CAHSPER_HTTP_BIND_ADDRESS |
Http server bind address. | string |
0.0.0.0 |
127.0.0.1 |
CAHSPER_HTTP_PORT |
Http server port. | int |
9001 |
9001 |
Cahsper backend (API server) use AWS Cognito for authentication. Please create AWS Cognito user pool and set the following system environment variable.
Property | Description | Type | Default | Example |
---|---|---|---|---|
CAHSPER_AWS_COGNITO_ISS |
AWS Cognito jwk iss | string |
- | https://cognito-idp.{region}.amazonaws.com/{userPoolId} |
CAHSPER_AWS_COGNITO_APP_CLIENT_ID |
AWS Cognito application Id | string |
- | - |
$ cd <source code dir>
$ sbt run
Full endpoints are please see the API document.
Create a new user
$ curl -D - -X POST -H "Authorization: Bearer 123456789" 127.0.0.1:9001/users
HTTP/1.1 201 Created
Server: akka-http/10.1.9
Date: Wed, 16 Oct 2019 13:06:05 GMT
Content-Type: application/json
Content-Length: 55 bytes
{
"name": "yoshinorin",
"createdAt": 1571231165
}
Get all users
$ curl -D - -X GET 127.0.0.1:9001/users
HTTP/1.1 200 OK
Server: akka-http/10.1.10
Date: Sun, 20 Oct 2019 12:45:24 GMT
Content-Type: application/json
Content-Length: 129
[
{
"name" : "JhonDue",
"createdAt" : 1571323331
},
{
"name" : "yoshinorin",
"createdAt" : 1571323750
}
]
Get all users comments
$ curl -D - -X GET 127.0.0.1:9001/comments
HTTP/1.1 200 OK
Server: akka-http/10.1.9
Date: Sat, 07 Sep 2019 13:28:57 GMT
Content-Type: application/json
Content-Length: 307
[
{
"id" : "04b89f7a-6d0c-46c5-87a2-2a35307765bf",
"user" : "yoshinorin",
"comment" : "test",
"createdAt" : 1567862313
},
{
"id" : "cc82737d-769d-11eb-a81e-663f66aa018c",
"user" : "TODO",
"comment" : "Hello Cahsper!!",
"createdAt" : 1567862760
}
]
Create new comment
$ curl -D - -X POST -H "Authorization: Bearer 123456789" -H "Content-Type: application/json" -d '{"comment":"Hello Cahsper!!"}' 127.0.0.1:9001/users/{userName}/comments
HTTP/1.1 201 Created
Server: akka-http/10.1.9
Date: Sat, 07 Sep 2019 13:26:01 GMT
Content-Type: application/json
Content-Length: 94
{
"id" : "cc82737d-769d-11eb-a81e-663f66aa018c",
"user" : "TODO",
"comment" : "Hello Cahsper!!",
"createdAt" : 1567862760
}
Stack | - |
---|---|
Scala | - |
Akka HTTP | HTTP server |
akka-http-cors | CORS for Akka HTTP |
Flyway | Database Migration |
quill | Database Library |
circe | JSON Library |
MariaDB | Database |
ScalaTest | Unit test |
Scalafmt | Code formatter |
GitHub Action | CI/CD |
Codacy | Check Code quality |
COVERALLS | Coverage report |
ReDoc | Generate API documentation |
GitHub Pages | Hosting API docuementation |
AWS Cognito | Authentication |
Nimbus JOSE | JWT validator |
This code is open source software licensed under the Apache 2.0 License.