Giter Site home page Giter Site logo

hxfj's Introduction

HXF WebServices

Simplicity is a prerequisite for reliability

Edsger W. Dijkstra


HXF Webservices or HXF-WS is part of HXF which stands for High productivity Cross-Platform Framework.

The idea behind HXF is to create a framework that boosts developer's productivity while persevering efficiency and performance features, the whole framework tries to implement advanced features while keeping the framework simple and easy to be understood.

HXF, at this stage, covers two main areas which are persistence and web services, they are covered by two sub-frameworks which are HXF-WS and HXF-P correspondingly.

HXF-WS is built on top of bare HTTP as a messaging protocol and JSON as a message format, messages exchanged with the server are very compact and easy to be serialized/de-serialized, based on this, HXF-WS is very efficient when compared to other frameworks that depend on heavier and more complex standards such as XML, SOAP and WSDL.

Simplicity does not mean that developers can't do everything using HXF-WS, on the contrary, they can create webservices that have all the required features while being light-weight, efficient and easy to be maintained.

Portability is the second design factor that was taken into consideration. While simplicity ensures reliability, it is also easier to build portable designs when the used standards are easy to be implemented, based on this, HXF-WS web services can easily be consumed from a wide range of clients.

For more information about HXF-WS and HXF please refer to documentation.

Quick Example

Using HXF-WS it is possible to expose any plain old java interface (POJI) as a web service, below is an example.

Let's have a plain java interface:

public interface ITestService {
    String sayHello(String s);
    String getStudentInfo(Student student);
    int getStudentCount(List<Student> studentList);
    int sum(int x, int y);
} 

The above interface is implemented using the code below:

public class TestService implements ITestService {

    @Override
    public String sayHello(String s1) {
        return "Hello, " + s1;
    }

    @Override
    public String getStudentInfo(Student student) {
        return student.toString();
    }

    @Override
    public int getStudentCount(List<Student> studentList) {
        return studentList.size();
    }

    @Override
    public int sum(int x, int y) {
        return x + y;
    }
}
public class Student {
    private int id;
    private String name;
    private float grade;
    private boolean graduated;

    public int getId() {
        return id;
    }

    // other getters and setters...
}

To expose the interface as a web service, the code below is used.

public class TestServlet extends HXFServlet {
    public TestServlet() {
        ServiceConfiguration serviceConfiguration = new ServiceConfiguration("TestService");
        serviceConfiguration.addInterfaceConfig("test", ITestService.class, TestService.class);
        this.runtimeConfiguration.setServiceConfiguration(serviceConfiguration);
    }
}

The above code exposes the ITest interface as a web service that can be accessed either using HTTP POST or HTTP GET. In the case of using GET, the call message is delivered as a query string. However, if POST is used, the call message is delivered using JSON. The output of the service is JSON by default. However, it is possible to extend the framework to include custom formats.

hxfj's People

Contributors

dependabot[bot] avatar kumait avatar

Watchers

 avatar  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.