com.github.tonivade.zeromock.api.HttpIOService Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.zeromock.api;
import static com.github.tonivade.purefun.monad.IOOf.toIO;
import static com.github.tonivade.zeromock.api.PreFilterK.filter;
import static java.util.Objects.requireNonNull;
import com.github.tonivade.purefun.Matcher1;
import com.github.tonivade.purefun.instances.IOInstances;
import com.github.tonivade.purefun.monad.IO;
import com.github.tonivade.purefun.monad.IO_;
import com.github.tonivade.purefun.type.Option;
public final class HttpIOService {
private final HttpServiceK serviceK;
public HttpIOService(String name) {
this(new HttpServiceK<>(name, IOInstances.monad()));
}
private HttpIOService(HttpServiceK serviceK) {
this.serviceK = requireNonNull(serviceK);
}
public String name() {
return serviceK.name();
}
public HttpIOService mount(String path, HttpIOService other) {
return new HttpIOService(serviceK.mount(path, other.serviceK));
}
public HttpIOService exec(IORequestHandler handler) {
return new HttpIOService(serviceK.exec(handler));
}
public ThenStep preFilter(Matcher1 matcher) {
return handler -> addPreFilter(matcher, handler);
}
public HttpIOService preFilter(PreFilter filter) {
return preFilter(filter.andThen(IO::pure)::apply);
}
public HttpIOService preFilter(IOPreFilter filter) {
return new HttpIOService(serviceK.preFilter(filter));
}
public HttpIOService postFilter(PostFilter filter) {
return postFilter(filter.andThen(IO::pure)::apply);
}
public HttpIOService postFilter(IOPostFilter filter) {
return new HttpIOService(serviceK.postFilter(filter));
}
public ThenStep when(Matcher1 matcher) {
return handler -> addMapping(matcher, handler);
}
public IO
© 2015 - 2025 Weber Informatics LLC | Privacy Policy