Skip to content

Instantly share code, notes, and snippets.

@TharmiganK
Last active July 28, 2023 05:24
Show Gist options
  • Save TharmiganK/d502da7714db50bf3fd1a8364f0addf1 to your computer and use it in GitHub Desktop.
Save TharmiganK/d502da7714db50bf3fd1a8364f0addf1 to your computer and use it in GitHub Desktop.
Conference Service Ballerina
import ballerina/http;
import ballerina/mime;
configurable string countryServiceUrl = ?;
configurable H2dbConfigs dbConfigs = ?;
service class ConferenceService {
*http:Service;
final ConferenceDBClient conferenceDBClient;
isolated function init() returns error? {
self.conferenceDBClient = check new (dbConfigs, countryServiceUrl);
}
@http:ResourceConfig {produces: [mime:APPLICATION_JSON]}
isolated resource function get conferences()
returns Conference[]|ConferenceServerError {
do {
return check self.conferenceDBClient->/conferences;
} on fail error err {
return {
body: {
message: "Error occurred while retrieving conferences",
cause: err.message()
}
};
}
}
@http:ResourceConfig {consumes: [mime:APPLICATION_JSON]}
isolated resource function post conferences(ConferenceRequest conference)
returns ConferenceServerError? {
do {
return check self.conferenceDBClient->/conferences.post(conference);
} on fail error err {
return {
body: {
message: "Error occurred while creating conference",
cause: err.message()
}
};
}
}
@http:ResourceConfig {produces: [mime:APPLICATION_JSON]}
isolated resource function get conferenceswithcountry()
returns ExtendedConference[]|ConferenceServerError {
do {
return check self.conferenceDBClient->/conferenceswithcountry;
} on fail error err {
return {
body: {
message: "Error occurred while retrieving conferences with country",
cause: err.message()
}
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment