The sample is based on a simple API written for a social-media site (like twitter) which has users, associated posts and followers. Following is the high level component diagram.
Following is the entity relationship diagram.
Following is the service description.
type SocialMedia service object {
*http:Service;
// users resource
resource function get users() returns User[]|error;
resource function get users/[int id]() returns User|UserNotFound|error;
resource function post users(NewUser newUser) returns http:Created|error;
resource function delete users/[int id]() returns http:NoContent|error;
// posts resource
resource function get users/[int id]/posts() returns PostMeta[]|UserNotFound|error;
resource function post users/[int id]/posts(NewPost newPost) returns http:Created|UserNotFound|PostForbidden|error;
};
Following are the features covered by the scenario.
- Writing REST APIs with verbs, URLs, data binding and status codes
- Accessing databases
- Configurability
- Data transformation with the data mapper
- HTTP client
- Resiliency - Retry
- Writing tests
- Using connectors - Slack
- OpenAPI specification, client stubs and central
- Adding validations
- Security - OAuth2
- Error handlers
- Ballerina concurrency
- Integrating a message broker
- Checkout the code base and move to the root folder
- Execute
build-docker-images.sh
script to generate the necessary docker images. - Execute
docker compose up
Note: When trying out feature 11 use port
9098
for the sentiment analysis endpoint.
- Setup a MySQL database
- Execute the script
init.sql
in db-setup
- Move to
sentiment-analysis-service
and executebal run
to start sentiment analysis service
-
Move to
sts-service
and executebal run
to start the Security Token Service (STS) service. The URL of the service ishttps://localhost:9445/oauth2/token
-
Move to
sentiment-analysis-service-secured
and executebal run
to start secured sentiment analysis service. Following are the OAuth2 details.clientId:
FlfJYKBD2c925h4lkycqNZlC2l4a
clientSecret:PJz0UhTJMrHOo68QQNpvnqAY_3Aa
scope:admin
Note: When trying out feature 11 use port
9098
for the sentiment analysis endpoint.
- Setup a NATS server
- To start the completed setup run
docker compose up -f docker-compose-complete.yml
- To send request open
social-media-request.http
file using VS Code withREST Client
extension