This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package odelia.restclient; | |
import javax.json.JsonObject; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package odelia.restclient; | |
import javax.inject.Inject; | |
import javax.json.JsonObject; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
import org.eclipse.microprofile.rest.client.inject.RestClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SwapiService swapiService = | |
RestClientBuilder.newBuilder() | |
.baseUrl(new URL("https://swapi.dev/api")) | |
.build(SwapiService.class); | |
JsonObject character = swapiService.getCharacter(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JsonObject character = swapiService.getCharacter("1"); | |
String name = character.getString("name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Inject | |
@RestClient | |
private SwapiService swapiService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RegisterRestClient | |
@Produces(MediaType.APPLICATION_JSON) | |
public interface SwapiService { | |
@GET | |
@Path("/people/{id}") | |
JsonObject getCharacter(@PathParam("id") String id); | |
@GET | |
@Path("/people") | |
JsonObject getPeople(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _makeAddItemCommand(Item item) { | |
{ Cart cart -> cart.addItem(item) } | |
} | |
def _makeRemoveItemCommand(Item item) { | |
{ Cart cart -> cart.removeItem(item) } | |
} | |
def actions = [ | |
_makeAddItemCommand(new Item(name: 'Item1', price: 1)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fpCart = new Cart() | |
// Create command | |
def addItem1 = makeAddItemCommand(fpCart, new Item(name: 'Item1', price: 1)) | |
// Invoke command | |
addItem1() | |
assert fpCart.items.keySet() == ['Item1'] as Set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def makeAddItemCommand(Cart cart, Item item) { | |
{ -> cart.addItem(item) } | |
} | |
def makeRemoveItemCommand(Cart cart, Item item) { | |
{ -> cart.removeItem(item) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MacroCartCommand implements CartCommand { | |
def commands = [] | |
MacroCartCommand leftShift(CartCommand command) { | |
commands << command | |
this | |
} | |
void setReceiver(Cart cart) { | |
commands*.cart = cart |
NewerOlder