Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/youngmonkeys/ezyhttp
support to interact to http (both http client and http server)
https://github.com/youngmonkeys/ezyhttp
http http-api http-client http-handler http-server restful restful-client restful-server
Last synced: 4 days ago
JSON representation
support to interact to http (both http client and http server)
- Host: GitHub
- URL: https://github.com/youngmonkeys/ezyhttp
- Owner: youngmonkeys
- License: apache-2.0
- Created: 2019-12-05T16:38:40.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-11T15:35:24.000Z (6 months ago)
- Last Synced: 2024-05-12T04:30:41.680Z (6 months ago)
- Topics: http, http-api, http-client, http-handler, http-server, restful, restful-client, restful-server
- Language: Java
- Size: 1.19 MB
- Stars: 12
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# ezyhttp
# Documentation
[https://youngmonkeys.org/projects/ezyhttp](https://youngmonkeys.org/projects/ezyhttp)
# Synopsis
EzyHttp is a library in EzyFox ecosystem, It supports to interact to HTTP (both http server and http client)
# Code Example
For full example you can take a look [the examples repository](https://github.com/tvd12/ezyfox-examples)
**1. Start HTTP Server application**
```java
import com.tvd12.ezyhttp.core.boot.EzyHttpApplicationBootstrap;
import com.tvd12.ezyhttp.server.core.annotation.ComponentsScan;@ComponentsScan({"packageA", "packageB"})
public class BootApp {public static void main(String[] args) throws Exception {
EzyHttpApplicationBootstrap.start(BootApp.class);
}
}
```**2. Add a controller**
```java
import com.tvd12.ezyfox.bean.annotation.EzyAutoBind;
import com.tvd12.ezyhttp.core.boot.test.data.Customer;
import com.tvd12.ezyhttp.core.boot.test.service.CustomerService;
import com.tvd12.ezyhttp.core.constant.StatusCodes;
import com.tvd12.ezyhttp.core.exception.HttpBadRequestException;
import com.tvd12.ezyhttp.core.exception.HttpNotFoundException;
import com.tvd12.ezyhttp.core.response.ResponseEntity;
import com.tvd12.ezyhttp.server.core.annotation.Controller;
import com.tvd12.ezyhttp.server.core.annotation.DoGet;
import com.tvd12.ezyhttp.server.core.annotation.DoPost;
import com.tvd12.ezyhttp.server.core.annotation.PathVariable;
import com.tvd12.ezyhttp.server.core.annotation.RequestBody;import lombok.Setter;
@Setter
@Controller("/api/v1/customer")
public class CustomerController {@EzyAutoBind
protected CustomerService customerService;
@DoGet("/{zone}/{name}")
public Customer getCustomer(@PathVariable("name") String name) {
Customer customer = customerService.getCustomer(name);
if(customer == null)
throw new HttpNotFoundException("customer: " + name + " not found");
return customer;
}
@DoPost("/add")
public ResponseEntity addCustomer(@RequestBody Customer customer) {
validateCustomer(customer);
customerService.save(customer);
return ResponseEntity.status(StatusCodes.NO_CONTENT).build();
}
protected void validateCustomer(Customer customer) {
Map errors = new HashMap<>();
if(customer == null) {
errors.put("customer", "required");
}
else {
if(customer.getName() == null)
errors.put("name", "required");
if(customer.getAge() < 1)
errors.put("age", "invalid");
}
if(errors.size() > 0)
throw new HttpBadRequestException(errors);
}
}
```**3. Add a service**
```java
import com.tvd12.ezyfox.bean.annotation.EzySingleton;
import com.tvd12.ezyhttp.core.boot.test.data.Customer;@EzySingleton
public class CustomerService {protected final Map customers = new HashMap<>();
public Customer getCustomer(String name) {
return customers.get(name);
}public void save(Customer customer) {
this.customers.put(customer.getName(), customer);
}
}
```# License
- Apache License, Version 2.0
# Support Us
[Make a Meaningful Donation](https://youngmonkeys.org/donate/)
Currently, our operating budget is fully supported by our own salaries, and all product development is still based on voluntary contributions from a few organization members. The low budget is causing significant difficulties for us. Therefore, with a clear roadmap and an ambitious goal to provide intellectual products for the community, we would greatly appreciate your support in the form of a donation to help us take further steps. Thank you in advance for your meaningful contributions!
# Contact Us
- Get in touch with us on [Facebook](https://www.facebook.com/youngmonkeys.org)
- Ask us on [stackask.com](https://stackask.com)
- Email us at [[email protected]](mailto:[email protected])
- Chat with us on [Discord](https://discord.gg/hKV2cbaT5h)