You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HTTP-RPC is an open-source framework for implementing RESTful and REST-like web services in Java. It is extremely lightweight and requires only a Java runtime environment and a servlet container. The entire framework is distributed as a single JAR file that is about 65KB in size, making it an ideal choice for applications where a minimal footprint is desired.
5
+
HTTP-RPC is an open-source framework for implementing RESTful and REST-like web services in Java. It is extremely lightweight and requires only a Java runtime environment and a servlet container. The entire framework is distributed as a single JAR file that is about 76KB in size, making it an ideal choice for applications where a minimal footprint is desired.
6
6
7
7
This guide introduces the HTTP-RPC framework and provides an overview of its key features.
8
8
@@ -23,6 +23,7 @@ This guide introduces the HTTP-RPC framework and provides an overview of its key
23
23
*[TemplateEncoder](#templateencoder)
24
24
*[BeanAdapter](#beanadapter)
25
25
*[ResultSetAdapter and Parameters](#resultsetadapter-and-parameters)
@@ -47,6 +48,8 @@ The HTTP-RPC framework includes the following classes:
47
48
*`RequestParameter` - annotation that associates a custom request parameter name with a method argument
48
49
*`ResourcePath` - annotation that associates a resource path with a service method
49
50
*`Response` - annotation that associates a custom response description with a service method
51
+
*`WebServiceException` - exception thrown when a service operation returns an error
52
+
*`WebServiceProxy` - web service invocation proxy
50
53
*`WebService` - abstract base class for web services
51
54
*`org.httprpc.io`
52
55
*`CSVDecoder` - class that decodes an iterable sequence of values from CSV
@@ -1066,5 +1069,51 @@ Data returned by the service might look like this:
1066
1069
}
1067
1070
```
1068
1071
1072
+
# WebServiceProxy
1073
+
The `WebServiceProxy` classis used to issue API requests to a server. This classprovides a single constructor that accepts the following arguments:
1074
+
1075
+
* `method` - the HTTP method to execute
1076
+
* `url` - the URL of the requested resource
1077
+
1078
+
Request headers and arguments are specified via the `setHeaders()` and `setArguments()` methods, respectively. Like HTML forms, arguments are submitted either via the query string or in the request body. Arguments for `GET`, `PUT`, and `DELETE` requests are always sent in the query string. `POST` arguments are typically sent in the request body, and may be submitted as either "application/x-www-form-urlencoded" or "multipart/form-data" (specified via the proxy's `setEncoding()` method). However, if the request body is provided via a custom request handler (specified via the `setRequestHandler()` method), `POST` arguments will be sent in the query string.
1079
+
1080
+
The `toString()` method is generally used to convert an argument to its string representation. However, `Date` instances are automatically converted to a long value representing epoch time. Additionally, `Iterable` instances represent multi-value parameters and behave similarly to `<select multiple>` tags in HTML. Further, when using the multi-part encoding, `URL` and `Iterable<URL>` values represent file uploads, and behave similarly to `<input type="file">` tags in HTML forms.
1081
+
1082
+
Service operations are invoked via one of the following methods:
The first version automatically deserializes a successful server response using `JSONDecoder`.The second allows a caller to provide a custom response handler. `ResponseHandler` is a functional interfacethat is defined as follows:
If a service returns an error response, a `WebServiceException` will be thrown. If the content type of the response is "text/plain", the body of the response will be provided in the exception message.
1099
+
1100
+
### Example
1101
+
The following code snippet demonstrates how `WebServiceProxy` might be used to access the operations of the simple math service discussed earlier:
This guide introduced the HTTP-RPC framework and provided an overview of its key features. For additional information, see the [examples](https://github.com/gk-brown/HTTP-RPC/tree/master/httprpc-test/src/main/java/org/httprpc/test).
0 commit comments