The VMJ Routing Library provides a simple and efficient way to handle HTTP request routing in the WinVMJ Framework. By using annotations, developers can define routes cleanly without complex configurations. This library supports multiple annotation-based route definitions, making API development more intuitive and maintainable.
This library provides an annotation-based routing system for handling HTTP requests efficiently. Several annotations are available to define routes and specify HTTP methods for better request handling.
@Route(url)Defines a route with the default HTTP method. Note: This annotation processes all requests, regardless of the HTTP request method.
Examples:
Implicit attribute definition:
import id.ac.ui.cs.prices.winvmj.core.Route;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Route("call/payment/save")
public void savePayment(VMJExchange vmjExchange) {
// Handle request
}
}
Explicit attribute definition:
import id.ac.ui.cs.prices.winvmj.core.Route;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Route(url = "call/payment/save")
public void savePayment(VMJExchange vmjExchange) {
// Handle request
}
}
@Route(url, method)Allows specifying the HTTP method explicitly.
Examples:
Implicit attribute definition:
import id.ac.ui.cs.prices.winvmj.core.Route;
import id.ac.ui.cs.prices.winvmj.core.RequestMethod;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Route("call/payment/save", RequestMethod.POST)
public void savePayment(VMJExchange vmjExchange) {
// Handle POST request
}
}
Explicit attribute definition:
import id.ac.ui.cs.prices.winvmj.core.Route;
import id.ac.ui.cs.prices.winvmj.core.RequestMethod;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Route(url = "call/payment/save", method = RequestMethod.POST)
public void savePayment(VMJExchange vmjExchange) {
// Handle POST request
}
}
| Method | Description |
|---|---|
GET |
Retrieves data from the server. |
HEAD |
Similar to GET but without the response body. |
POST |
Submits data to be processed. |
PUT |
Updates or creates a resource. |
PATCH |
Partially updates a resource. |
DELETE |
Removes a resource. |
OPTIONS |
Describes the communication options. |
UNSPECIFIED |
Default method when no specific method is defined. |
@Get(url)
A shortcut for defining a GET route.
Example:
import vmj.routing.route.annotations.Get;
import vmj.routing.route.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Get("call/payment/list")
public void getAllPayment(VMJExchange vmjExchange) {
// Handle GET request
}
}
@Head(url)
A shortcut for defining a HEAD route.
Example:
import id.ac.ui.cs.prices.winvmj.core.annotations.Head;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Head("call/payment")
public void handleHeadPayment(VMJExchange vmjExchange) {
// Handle HEAD request
}
}
@Post(url)
A shortcut for defining a POST route.
Example:
import id.ac.ui.cs.prices.winvmj.core.annotations.Post;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Post("call/payment/save")
public void savePayment(VMJExchange vmjExchange) {
// Handle POST request
}
}
@Put(url)
A shortcut for defining a PUT route.
Example:
import id.ac.ui.cs.prices.winvmj.core.annotations.Put;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Put("call/payment/update")
public void updatePaymentPost(VMJExchange vmjExchange) {
// Handle PUT request
}
}
@Patch(url)
A shortcut for defining a PATCH route.
Example:
import id.ac.ui.cs.prices.winvmj.core.annotations.Delete;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Patch("call/payment/update")
public void updatePaymentPut(VMJExchange vmjExchange) {
// Handle PATCH request
}
}
@Delete(url)
A shortcut for defining a DELETE route.
Example:
import vmj.routing.route.annotations.Delete;
import vmj.routing.route.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Delete("call/payment/delete")
public void deletePayment(VMJExchange vmjExchange) {
// Handle DELETE request
}
}
@Options(url)
A shortcut for defining a OPTIONS route.
Example:
import id.ac.ui.cs.prices.winvmj.core.annotations.Options;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Options("call/payment")
public void optionPayment(VMJExchange vmjExchange) {
// Handle OPTIONS request
}
}
This library provides CORS implementation to restrict cross-origin requests by allowing only specific domains and HTTP methods.
By default, it allows all domains and the GET, POST, PUT, PATCH, and DELETE methods.
If modification is needed, the configuration file for CORS can be found in {ProductName}/cors.properties.
You can modify the cors.properties to allow custom origins, like this:
allowedOrigin = http://example1.com, https://example2.com
allowedMethod = GET, POST
This library provides several built-in exceptions to handle various routing errors efficiently. These exceptions help developers debug issues related to request handling, invalid routes, and other HTTP-related errors. For a complete list of error codes and their descriptions, refer to the VMJ Error Code Wiki.
This library provides functionality to exclude specific endpoints from the system. This feature allows developers to temporarily disable endpoints that may be affected by bugs, security concerns, or other issues requiring them to be hidden from use.
To exclude an endpoint, simply add it to the endpoints.json file as follows:
{
"excludes": [
"call/user",
"call/user/detail",
...
]
}
The endpoints.json file is located in:
- {ProductName}/
- {product-line-name}.{product}.{product-name}/
- sql/
- endpoints.json
- run.bat
...
v2.2.0:
@Route(url, method), allowing explicit HTTP method specification.@Get(url), @Head(url), @Post(url), @Put(url), @Patch(url), @Delete(url), and @Options(url) for cleaner and more explicit route definitions.v2.1.9:
v2.1.8: