Giter VIP home page Giter VIP logo

opa-java-client's Introduction

opa-java-client

Maven Central build

OPA java client is a wrapper for OPA REST API. The goal was to create client that is lightweight and framework independent. It's built for current Bisnode needs, including:

  • creating documents
  • creating policies
  • querying for documents

Installation

Prerequisites: Java 11 or higher

Add library using maven:

<dependency>
    <groupId>com.bisnode.opa</groupId>
    <artifactId>opa-java-client</artifactId>
    <version>{version}</version>
</dependency>

or Gradle

implementation 'com.bisnode.opa:opa-java-client:{version}'

Usage

Our library is using Jackson for (de)serialization so, objects that you are passing/retrieving using this client should have either proper Jackson-friendly configuration or - the solution working in most cases - getters and setters for fields you want to pass/retrieve to/from OPA. More information about Jackson.

Query for document

        OpaQueryApi client = OpaClient.builder()
                                .opaConfiguration("http://localhost:8181")
                                .build();

        DesiredResponse response = client.queryForDocument(new QueryForDocumentRequest(yourDTO, "path/to/document"), DesiredResponse.class);
        
        // Do whatever you like with the response

####Example Example project is in examples/query-for-document directory.

Create policy

        OpaPolicyApi client = OpaClient.builder()
                                     .opaConfiguration("http://localhost:8181")
                                     .build();

        void createOrUpdatePolicy(new OpaPolicy("your_policy_id", "content of the policy"));

Create document

        OpaDataApi client = OpaClient.builder()
                                     .opaConfiguration("http://localhost:8181")
                                     .build();

        void createOrOverwriteDocument(new OpaDocument("path/to/document", "content of document (json)"));

Error handling

Error handling is done via exceptions. This means that if any error occurs, runtime exception which is subclass of OpaClientException is thrown. For now, there is simple error message returned.

OpaServerConnectionException is thrown when connection problems with OPA server occur.

Interface segregation

Every OPA (Data, Policy, Query) API has it's own interface. So, for example, if you want to use client only for querying, you can use OpaQueryApi as projection. Thanks to that, in your code there will be exposed only methods that are needed by you, while not allowing to mess with policies and data.

Available interface projections:

  • OpaQueryApi
  • OpaPolicyApi
  • OpaDataApi

Developing and building

Build process and dependency management is done using Gradle. Tests are written in spock.

Contribution

Interested in contributing? Please, start by reading this document.

opa-java-client's People

Contributors

anderseknert avatar irodzik avatar lkadalski avatar lukasz-kaminski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.