https://github.com/blobbybilb/java-helpers
https://github.com/blobbybilb/java-helpers
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/blobbybilb/java-helpers
- Owner: blobbybilb
- Created: 2023-11-04T23:52:16.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-06T23:00:02.000Z (over 2 years ago)
- Last Synced: 2024-05-30T02:14:40.926Z (about 2 years ago)
- Language: Java
- Size: 97.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# blobbybilb/java-helpers
**Goal:** Fix Java
(jk, that's probably impossible)
**Realistic Goal:** Make java a little less annoying to make stuff with.
### Actually though, what is this?
A set of Java classes that help with commonly used functionality,
so you don't have to reimplement it everytime (or use Maven/Gradle in a small project).
You can use this as a single jar file that you just copy into your project directory,
because it's intended for projects where the extra complexity/annoyingness of
java build systems/package management is not worth it.
### What does it have?
- A custom JSON parser [(more info)](https://github.com/blobbybilb/java-helpers/tree/master/src/Helpers/JSON#readme)
- And a JSON serializer too
- HTTP client (single line HTTP POST/GET)
- HTTP server (a little WIP but should work)
- A key-value store
### Docs
#### JSON
```java
// Parse JSON
Object data = new JSONParser(jsonString).parse();
// Serialize JSON
String jsonString = new JSONSerializer(data).serialize();
// JSON-able Types: Map (JSON object), List (JSON array), String, Number, Boolean, null
```
#### KV Store
```java
// Create a KV store, SomeType is the type of the value which can be a JSON-able type (see above)
KVStore kv = new KVStore<>(dataDirectoryString);
// Set a value
kv.set("key", value); // value of type SomeType
// Get a value
SomeType value = kv.get("key"); // returns value of type SomeType, throws KVStoreException if key doesn't exist or data is corrupted/invalid
// Delete a value
kv.del("key");
```
#### HTTP Client
```java
// HTTP GET
String response = Request.get("http://example.com");
// HTTP POST
String response = Request.post("http://example.com", Map); // Form data body
String response = Request.post("http://example.com", String, Helpers.HTTP.ContentType); // Other data body types
```
#### HTTP Server
```java
Server server = new Server(3000);
server.get
```