Skip to content

Instantly share code, notes, and snippets.

View Sam-Kruglov's full-sized avatar

Sam Kruglov Sam-Kruglov

View GitHub Profile
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Created January 10, 2018 16:17
GET localhost:8080/users/1
{
"username": "jsmith",
"firstName": "John",
"lastName": "Smith",
"_links": {
"self": {
"href": "http://localhost:8080/users/1"
},
"user": {
"href": "http://localhost:8080/users/1"
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 11, 2018 04:10
DTO GET localhost:8080/users/search
{
"_links": {
"getUsername": {
"href": "http://localhost:8080/users/search/username{?id}",
"templated": true
},
"self": {
"href": "http://localhost:8080/users/search"
}
}
@Sam-Kruglov
Sam-Kruglov / UserController.java
Last active January 11, 2018 10:14
DTO Alter "getUsername" to have links
@RepositoryRestController
public class UserController {
private final RepositoryEntityLinks links;
private final UserRepository userRepository;
// all arg constructor
@GetMapping("users/search/username")
public ResponseEntity<Resource<UserUsername>> addLinksToUserUsername(@RequestParam("id") Long id){
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 11, 2018 05:13
DTO Accessing GET localhost:8080/users/search/username?id=1 with links
{
"username": "jsmith",
"_links": {
"self": {
"href": "http://localhost:8080/users/search/username{?id}",
"templated": true
},
"user": {
"href": "http://localhost:8080/users/1"
}
@Sam-Kruglov
Sam-Kruglov / UserRepository.java
Last active January 11, 2018 10:19
Projection recursive open
public interface UserRepository extends CrudRepository<User, Long> {
@RestResource(path = "username", rel = "getUsername")
UserUsernameAndGroupName findUsernameAndGroupNameById(@Param("id") Long id);
interface UserUsernameAndGroupName {
String getUsername();
default String getGroupName() {
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Created January 11, 2018 09:56
Projection recursive open localhost:8080/users/search/username?id=1
{
"username": "jsmith",
"groupName": "A"
}
@Sam-Kruglov
Sam-Kruglov / UserUsername.java
Last active January 11, 2018 11:18
Projection simple
package com.samkruglov.entities.projections;
@Projection(name = "username-only", types = User.class)
public interface UserUsername {
String getUsername();
}
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 11, 2018 11:13
Projection GET localhost:8080/users/1
{
"username": "jsmith",
"firstName": "John",
"lastName": "Smith",
"_links": {
"self": {
"href": "http://localhost:8080/users/1"
},
"user": {
"href": "http://localhost:8080/users/1{?projection}",
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 11, 2018 11:13
Projection GET localhost:8080/users
{
"_embedded": {
"users": []
},
"_links": {
"self": {
"href": "http://localhost:8080/users"
},
"profile": {
"href": "http://localhost:8080/profile/users"
@Sam-Kruglov
Sam-Kruglov / REST_response.json
Last active January 11, 2018 11:18
Projection GET localhost:8080/profile/users
{
"alps": {
"version": "1.0",
"descriptors": [
{
"id": "get-users",
"name": "users",
"type": "SAFE",
"rt": "#user-representation",
"descriptors": [