Quick Start
Here you will learn
- Integrate Palmyra in SpringBoot application
- How to Create a Request/Response format using Pojo classes
- Handler to perform query Operations
- How to access the published API
Integrate Palmyra in SpringBoot Application
Add palmyra dependencey in project build configuration, example given for gradle build.
repositories {
mavenCentral()
maven {
url "https://repo.palmyralabs.com/releases"
}
}
dependencies {
.. spring dependencies
implementation 'com.palmyralabs.palmyra:palmyra-spring:1.0.0'
}
and in the SpringBoot main class, Import PalmyraSpringConfiguration The starter java class would be as below.
@SpringBootApplication
@Import({PalmyraSpringConfiguration.class})
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
Define API Schema
The Query Schema - API request and response format is defined using annotations in a pojo class
Using @PalmyraType
annotation, the primary table for query shall be defined. The @PalmyraField
will be used to define the properties for columns being queried.
An example to query User object is as follows.
@PalmyraType(type="User")
public class User {
@PalmyraField(attribute="email", sort=true, search=true)
private String loginName;
@PalmyraField(attribute="userName")
private String name;
@PalmyraField(attribute="dob")
private LocalDate dateOfBirth;
}
Query Handler
A component class implementing QueryHandler
interface should be mapped using two Annotations.
- @CrudMapping - to define the service endPoint
- @PalmyraTypeRef - provide the pojo class reference
@Component
@CrudMapping(mapping="/v1/admin/user", type=User.class)
public class UserQueryHandler implements QueryHandler {
@Override
public int aclCheck(Tuple item, HandlerContext ctx) {
return ACLRights.ALL;
}
}
Access the user Query API
By default, the api will be published under /api/<crudMapping value>
. Here the user details can be queried using
curl --request GET \
--url 'http://localhost:8080/palmyra/v1/admin/user \
--header 'Content-Type: application/json'
- Add authentication details as needed