EN
Spring Boot - best way to prevent sending overhead data in URL per each API request?
1 answers
5 points
I am developing web service that provides API that intermediates in some operations with desired web service.
Application concept:
xxxxxxxxxx
1
Client Web Browser ---> My Web Service (+ My API) ---> Desired Web Service
My web service, needs in each request the following path prefix:
xxxxxxxxxx
1
/clients/{clientId}/tenants/{tenantId}/divisions/{divisionId}/employees/{employeeId}
It makes URLs not clear.
Is there some way to reduce that overhead information?
I was thinking about putting it into HTTP headers but it requires setting it each time also.
1 answer
3 points
Consider storing clientId
, tenantId
, divisionId
and employeeId
variables in session.
Example user login concept:
xxxxxxxxxx
1
"/path/to/login-user") (
2
3
public Object loginUser(HttpServletRequest request, UserData data) {
4
// ...
5
// user data checking ...
6
// ...
7
HttpSession session = request.getSession();
8
session.setAttribute("LOGGED_CLIENT_ID", data.clientId);
9
session.setAttribute("LOGGED_TENANT_ID", data.tenantId);
10
session.setAttribute("LOGGED_DIVISION_ID", data.divisionId);
11
session.setAttribute("LOGGED_EMPLOYEE_ID", data.employeeId);
12
// ...
13
}
Example some action concept:
xxxxxxxxxx
1
"/path/to/action-name") (
2
3
public Object doAction(HttpServletRequest request/*, ... */) {
4
// ...
5
// user privileges checking ...
6
// ...
7
HttpSession session = request.getSession();
8
Long clientId = (Long) session.getAttribute("LOGGED_CLIENT_ID");
9
Long tenantId = (Long) session.getAttribute("LOGGED_TENANT_ID");
10
Long divisionId = (Long) session.getAttribute("LOGGED_DIVISION_ID");
11
Long employeeId = (Long) session.getAttribute("LOGGED_EMPLOYEE_ID");
12
// ...
13
}
See also
0 commentsShow commentsAdd comment