kotowari-restful

Kotowari-Restful is a RESTful API specific framework.

License

License

Categories

Categories

Net
GroupId

GroupId

net.unit8.enkan
ArtifactId

ArtifactId

kotowari-restful
Last Version

Last Version

0.2.4
Release Date

Release Date

Type

Type

jar
Description

Description

kotowari-restful
Kotowari-Restful is a RESTful API specific framework.
Source Code Management

Source Code Management

https://github.com/enkan/kotowari-restful

Download kotowari-restful

How to add to project

<!-- https://jarcasting.com/artifacts/net.unit8.enkan/kotowari-restful/ -->
<dependency>
    <groupId>net.unit8.enkan</groupId>
    <artifactId>kotowari-restful</artifactId>
    <version>0.2.4</version>
</dependency>
// https://jarcasting.com/artifacts/net.unit8.enkan/kotowari-restful/
implementation 'net.unit8.enkan:kotowari-restful:0.2.4'
// https://jarcasting.com/artifacts/net.unit8.enkan/kotowari-restful/
implementation ("net.unit8.enkan:kotowari-restful:0.2.4")
'net.unit8.enkan:kotowari-restful:jar:0.2.4'
<dependency org="net.unit8.enkan" name="kotowari-restful" rev="0.2.4">
  <artifact name="kotowari-restful" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.unit8.enkan', module='kotowari-restful', version='0.2.4')
)
libraryDependencies += "net.unit8.enkan" % "kotowari-restful" % "0.2.4"
[net.unit8.enkan/kotowari-restful "0.2.4"]

Dependencies

compile (5)

Group / Artifact Type Version
net.unit8.enkan : kotowari jar 0.10.0
org.hibernate.validator : hibernate-validator jar 6.0.17.Final
org.glassfish : javax.el jar 3.0.0
com.fasterxml.jackson.core : jackson-databind jar 2.9.9.3
net.unit8.enkan : enkan-component-jackson jar 0.10.0

test (4)

Group / Artifact Type Version
com.fasterxml.jackson.jaxrs : jackson-jaxrs-json-provider jar 2.9.9
org.junit.jupiter : junit-jupiter-api jar 5.5.2
org.assertj : assertj-core jar 3.13.2
org.junit.jupiter : junit-jupiter-engine jar 5.5.2

Project Modules

There are no modules declared in this project.

Kotowari Restful

Kotowari-Restful is a RESTful API specific framework.

Resource

A resource class should implements the Resource interface.

public interface Resource {
    Function<RestContext, ?> getFunction(DecisionPoint point);
}

Class resource

A class resource is a useful for defining resource functions in a single class file as following.

public class AddressesResource {
    @Inject
    private BeansValidator validator;

    @Inject
    private BeansConverter beansConverter;

    @Decision(value = MALFORMED, method={"GET"})
    public Problem isMalformed(Parameters params, RestContext context) {
        AddressSearchParams searchParams = beansConverter.createFrom(params, AddressSearchParams.class);
        context.putValue(searchParams);
        Set<ConstraintViolation<AddressSearchParams>> violations = validator.validate(searchParams);
        return violations.isEmpty() ? null : Problem.fromViolations(violations);
    }

    @Decision(value = MALFORMED, method={"POST"})
    public Problem isPostMalformed(Address address) {
        Set<ConstraintViolation<Address>> violations = validator.validate(address);
        return violations.isEmpty() ? null : Problem.fromViolations(violations);
    }

    @Decision(HANDLE_OK)
    public List<Address> handleOk(AddressSearchParams params, EntityManager em) {
        CriteriaBuilder builder = em.getCriteriaBuilder();
        CriteriaQuery<Address> query = builder.createQuery(Address.class);
        Root<Address> root = query.from(Address.class);
        query.select(root);

        return em.createQuery(query)
                .setFirstResult(params.getOffset())
                .setMaxResults(params.getLimit())
                .getResultList();
    }

    @Decision(POST)
    public Address handleCreated(Address address, EntityManager em) {
        EntityTransactionManager tx = new EntityTransactionManager(em);
        tx.required(() -> em.persist(address));
        return address;
    }
}

A class resource has a parent resource. It's used to define default resource functions.

ResourceInvokerMiddleware

ResourceInvokerMiddleware is a middleware for dispatching a request to the resource matching by routing.

net.unit8.enkan
Enkan framework

Versions

Version
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0