-
Notifications
You must be signed in to change notification settings - Fork 140
[DOC] Restful URI patterns URLs with resources
It is common if you are updating an object to do a PUT, and if you are adding a new object to do POST.
GET method should never modify data. Use POST to add and PUT to modify. Use DELETE to remove an item.
It also makes a lot of sense to organize you resources in collections.
A collection of employees in a Restful URL is generally /${rootURI}/employee/
.
To add to a list of employees you would either POST or PUT to the /${rootURI}/employee/
.
Let's say you wanted to add a phone_number to an employee who resided in a certain department.
You could POST or PUT the phone number at this location /department/{departmentId}/employee/{employeeId}/phoneNumber/
.
package io.advantageous.qbit.service.rest.endpoint.tests.services;
import io.advantageous.qbit.annotation.PathVariable;
import io.advantageous.qbit.annotation.RequestMapping;
import io.advantageous.qbit.annotation.RequestMethod;
import io.advantageous.qbit.service.rest.endpoint.tests.model.Department;
import io.advantageous.qbit.service.rest.endpoint.tests.model.Employee;
import io.advantageous.qbit.service.rest.endpoint.tests.model.PhoneNumber;
import java.util.*;
import java.util.function.Predicate;
@RequestMapping("/hr")
public class HRService {
final Map<Integer, Department> departmentMap = new HashMap<>();
@RequestMapping("/department/")
public List<Department> getDepartments() {
return new ArrayList<>(departmentMap.values());
}
@RequestMapping(value = "/department/{departmentId}/", method = RequestMethod.POST)
public boolean addDepartments(@PathVariable("departmentId") Integer departmentId,
final Department department) {
departmentMap.put(departmentId, department);
return true;
}
@RequestMapping(value = "/department/{departmentId}/employee/", method = RequestMethod.POST)
public boolean addEmployee(@PathVariable("departmentId") Integer departmentId,
final Employee employee) {
final Department department = departmentMap.get(departmentId);
if (department == null) {
throw new IllegalArgumentException("Department " + departmentId + " does not exist");
}
department.addEmployee(employee);
return true;
}
@RequestMapping(value = "/department/{departmentId}/employee/{employeeId}", method = RequestMethod.GET)
public Employee getEmployee(@PathVariable("departmentId") Integer departmentId,
@PathVariable("employeeId") Long employeeId) {
final Department department = departmentMap.get(departmentId);
if (department == null) {
throw new IllegalArgumentException("Department " + departmentId + " does not exist");
}
Optional<Employee> employee = department.getEmployeeList().stream().filter(new Predicate<Employee>() {
@Override
public boolean test(Employee employee) {
return employee.getId() == employeeId;
}
}).findFirst();
if (employee.isPresent()){
return employee.get();
} else {
throw new IllegalArgumentException("Employee with id " + employeeId + " Not found ");
}
}
public Map<Integer, Department> getDepartmentMap() {
return departmentMap;
}
@RequestMapping(value = "/department/{departmentId}/employee/{employeeId}/phoneNumber/",
method = RequestMethod.POST)
public boolean addPhoneNumber(@PathVariable("departmentId") Integer departmentId,
@PathVariable("employeeId") Long employeeId,
PhoneNumber phoneNumber) {
Employee employee = getEmployee(departmentId, employeeId);
employee.addPhoneNumber(phoneNumber);
return true;
}
@RequestMapping(value = "/department/{departmentId}/employee/{employeeId}/phoneNumber/")
public List<PhoneNumber> getPhoneNumbers(@PathVariable("departmentId") Integer departmentId,
@PathVariable("employeeId") Long employeeId) {
Employee employee = getEmployee(departmentId, employeeId);
return employee.getPhoneNumbers();
}
}
QBit Website What is Microservices Architecture?
QBit Java Micorservices lib tutorials
The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
Reactive Programming, Java Microservices, Rick Hightower
Java Microservices Architecture
[Microservice Service Discovery with Consul] (http://www.mammatustech.com/Microservice-Service-Discovery-with-Consul)
Microservices Service Discovery Tutorial with Consul
[Reactive Microservices] (http://www.mammatustech.com/reactive-microservices)
[High Speed Microservices] (http://www.mammatustech.com/high-speed-microservices)
Reactive Microservices Tutorial, using the Reactor
QBit is mentioned in the Restlet blog
All code is written using JetBrains Idea - the best IDE ever!
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting
Tutorials
- QBit tutorials
- Microservices Intro
- Microservice KPI Monitoring
- Microservice Batteries Included
- RESTful APIs
- QBit and Reakt Promises
- Resourceful REST
- Microservices Reactor
- Working with JSON maps and lists
__
Docs
Getting Started
- First REST Microservice
- REST Microservice Part 2
- ServiceQueue
- ServiceBundle
- ServiceEndpointServer
- REST with URI Params
- Simple Single Page App
Basics
- What is QBit?
- Detailed Overview of QBit
- High level overview
- Low-level HTTP and WebSocket
- Low level WebSocket
- HttpClient
- HTTP Request filter
- HTTP Proxy
- Queues and flushing
- Local Proxies
- ServiceQueue remote and local
- ManagedServiceBuilder, consul, StatsD, Swagger support
- Working with Service Pools
- Callback Builders
- Error Handling
- Health System
- Stats System
- Reactor callback coordination
- Early Service Examples
Concepts
REST
Callbacks and Reactor
Event Bus
Advanced
Integration
- Using QBit in Vert.x
- Reactor-Integrating with Cassandra
- Using QBit with Spring Boot
- SolrJ and service pools
- Swagger support
- MDC Support
- Reactive Streams
- Mesos, Docker, Heroku
- DNS SRV
QBit case studies
QBit 2 Roadmap
-- Related Projects
- QBit Reactive Microservices
- Reakt Reactive Java
- Reakt Guava Bridge
- QBit Extensions
- Reactive Microservices
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting