Git Product home page Git Product logo

jcoon's Introduction

jCoon

This library is created to simplify the process of creating REST client in Spring Framework. Instead writing a large amount of identical code you should just create java interface and add a few annotations.

Build Status

Maven repository

Add maven repository :

<repositories>
     <repository>
         <id>oss-sonatype-staging</id>
         <name>sonatype</name>
         <url>https://oss.sonatype.org/content/groups/staging</url>
     </repository>
</repositories>

and dependency to pom.xml:

<dependency>
    <groupId>com.art4ul</groupId>
    <artifactId>jcoon</artifactId>
    <version>0.3.2-SNAPSHOT</version>
</dependency>

Example

To create Rest client you need to perform only 3 steps:

  1. Add the following bean definition in spring application context:

    <bean class="com.art4ul.jcoon.bean.RestClientAnnotationBeanPostProcessor"/>

or if you want use custom RestTemplate with message converter:

```xml
<bean id="jsonMarshaller" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate" depends-on="jsonMarshaller">
     <property name="messageConverters" ref="jsonMarshaller"/>
</bean>

<bean class="com.art4ul.jcoon.bean.RestClientAnnotationBeanPostProcessor" depends-on="restTemplate">
     <constructor-arg index="0" ref="restTemplate"/>
</bean>
```
  1. Create interface and discribe methods using Spring Web annotations like: @RequestMapping, @RequestParam, @RequestBody etc.

    @RequestMapping("example1")
    public interface ExampleRestClient {
        @BaseUrl
        void setBaseUrl(String url);
    
        @RequestMapping(value = "/exampleGet", method = RequestMethod.GET)
        ResultModel exampleGetRequest(@RequestParam("name") String name);
    
    }
  2. And use it in your code:

    @Service
    public class TestService {
    
        @RestClient
        private ExampleRestClient restClient;
    
        public void doTest() {
    
            restClient.setBaseUrl("http://localhost:8080");
    
            ResultModel result = restClient.exampleGetRequest("world");
        }
    }

For more information see the sample project

jcoon's People

Contributors

art4ul avatar

Stargazers

 avatar

Watchers

 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.