All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datafx.crud.rest.RestCrudService Maven / Gradle / Ivy

package org.datafx.crud.rest;

import org.datafx.crud.BasicCrudService;
import org.datafx.util.EntityWithId;
import org.datafx.util.HttpMethods;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

public class RestCrudService, T> extends BasicCrudService {

    public RestCrudService(final String baseUrl) {
        super(new RestCall>((o) -> createUrl(baseUrl + "/all"), HttpMethods.GET, null, new JsonBasedResponseDataHandler<>()),
                new RestCall((o) -> createUrl(baseUrl + "/" + o), HttpMethods.GET, null, new JsonBasedResponseDataHandler<>()),
                new RestCall((o) -> createUrl(baseUrl + "/" + o), HttpMethods.DELETE, null, null),
                new RestCall((o) -> createUrl(baseUrl), HttpMethods.PUT, new JsonBasedRequestDataHandler<>(), new JsonBasedResponseDataHandler<>()),
                new RestCall((o) -> createUrl(baseUrl), HttpMethods.POST, new JsonBasedRequestDataHandler<>(), new JsonBasedResponseDataHandler<>())
                );
    }

    private static URL createUrl(String url) {
        try {
            return new URL(url);
        } catch (MalformedURLException e) {
            throw new RuntimeException("TODO");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy