📜  darkhub - Java (1)

📅  最后修改于: 2023-12-03 15:30:21.738000             🧑  作者: Mango

DarkHub - Java

DarkHub - Java Logo

DarkHub is a powerful and versatile Java library created for developers who desire an easy-to-use solution for common tasks such as HTTP requests, JSON parsing, and database querying. With its simple API and extensive documentation, it is the perfect choice for building robust and reliable applications.

Features
  • Easy-to-use API
  • HTTP Request handling
  • JSON parsing and serialization
  • Database querying (using JDBC)
  • Support for multiple databases including MySQL, PostgreSQL and SQLite
  • Built-in connection pooling
  • Logging (using Log4j)
  • Configurable settings (using a properties file)
Installation

To use DarkHub in your project, add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.darkhub</groupId>
    <artifactId>darkhub-java</artifactId>
    <version>1.0.0</version>
</dependency>

Alternatively, download the JAR file from the GitHub releases page and include it in your project's classpath.

HTTP Request Handling

DarkHub provides a simple and intuitive API for making HTTP requests. To make a GET request:

HttpResponse response = DarkHub.get("https://example.com");
System.out.println(response.getBody());

Similarly, to make a POST request:

HttpResponse response = DarkHub.post("https://example.com", "{\"key\": \"value\"}");
System.out.println(response.getStatusCode());
JSON Parsing

DarkHub makes it easy to parse and serialize JSON data. To parse a JSON string:

JSONObject jsonObject = DarkHub.jsonParse("{\"name\": \"John\", \"age\": 30}");
System.out.println(jsonObject.getString("name"));

To serialize an object to JSON:

Person person = new Person("John", 30);
String json = DarkHub.jsonSerialize(person);
System.out.println(json);
Database Querying

DarkHub provides a simple and easy-to-use API for querying databases using JDBC. To establish a database connection:

DatabaseConnection connection = DarkHub.connectToDatabase("jdbc:mysql://localhost:3306/mydatabase", "root", "password");

To run a query:

DatabaseResultSet result = DarkHub.executeQuery(connection, "SELECT * FROM users");
while (result.next()) {
    System.out.println(result.getString("username"));
}
Logging

DarkHub uses Log4j for logging. To log a message:

DarkHub.log(LogLevel.INFO, "This is a log message.");
Configuration

DarkHub is highly configurable and can be customized using a properties file. To configure DarkHub, create a file named darkhub.properties in your project classpath and add the following properties:

# Database configuration
database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/mydatabase
database.username=root
database.password=password

# Logging configuration
logging.level=INFO
Conclusion

DarkHub is a powerful and versatile Java library that makes it easy to handle HTTP requests, parse JSON data, query databases, and log messages. Its simplicity and ease of use make it the perfect choice for developers of all levels.