Skip to content

Commit

Permalink
Add dev reference
Browse files Browse the repository at this point in the history
  • Loading branch information
olle committed Jul 10, 2024
1 parent 49b3406 commit 16ef8c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 39 deletions.
6 changes: 5 additions & 1 deletion xdocs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export default defineConfig({
search: {
provider: "local",
},
nav: [{ text: "Home", link: "/" }],
nav: [
{ text: "Home", link: "/" },
{ text: "Guide", link: "/guide/what-is-query-response" },
{ text: "Reference", link: "/reference/developers-reference" },
],
sidebar: [
{
text: "Guide",
Expand Down
7 changes: 0 additions & 7 deletions xdocs/.vitepress/theme/custom.css

This file was deleted.

5 changes: 0 additions & 5 deletions xdocs/.vitepress/theme/index.js

This file was deleted.

49 changes: 23 additions & 26 deletions xdocs/reference/developers-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ composition of _initial_, _conditional_, an optional _informal_ and
exactly one _terminal_ method call. In the table below is a short review of the
different builder methods and their types.


### `QueryBuilder` fluid API method types

| Method | Type | Description |
Expand Down Expand Up @@ -190,11 +189,11 @@ The _informal_ builder feature, allows for transparency into queries that may
have to be observed.

```java
return queryBuilder.queryFor("offers/rental", NewOffer.class)
.takingAtLeast(3)
.waitingFor(400)
.onError(error -> LOG.error("Failure!", error))
.orThrow(TooFewOffersConstraintException::new);
return queryBuilder.queryFor("offers/rental", NewOffer.class)
.takingAtLeast(3)
.waitingFor(400)
.onError(error -> LOG.error("Failure!", error))
.orThrow(TooFewOffersConstraintException::new);
```

## `ResponseBuilder`
Expand Down Expand Up @@ -251,17 +250,15 @@ _batching_, which can be used to control the transfer of data to some degree.

The table below shows a summary of the builder methods and types.

[cols="1,1,3"]
.`ResponseBuilder` fluid API method types
|===
| Method | Type | Description
### `ResponseBuilder` fluid API method types

| `respondTo(..)` | _initial_ | Creates a new builder for a query
| `withAll()` | _batching_ | Specifies NO batches
| `withBatchesOf(..)` | _batching_ | Sets the batch size of responses
| `from(..)` | _terminal_ | Terminates with some given response data
| `suppliedBy(..)` | _terminal_ | Terminates with some supplied response data
|===
| Method | Type | Description |
| ------------------- | ---------- | ------------------------------------------- |
| `respondTo(..)` | _initial_ | Creates a new builder for a query |
| `withAll()` | _batching_ | Specifies NO batches |
| `withBatchesOf(..)` | _batching_ | Sets the batch size of responses |
| `from(..)` | _terminal_ | Terminates with some given response data |
| `suppliedBy(..)` | _terminal_ | Terminates with some supplied response data |

Let's take a closer look at each of the builder method types.
Expand All @@ -271,7 +268,7 @@ At the moment there's only one _initial_ method for building responses. It is
declared as:

```java
public <T> ChainingResponseBuilder<T> respondTo(String term, Class<T> type)
public <T> ChainingResponseBuilder<T> respondTo(String term, Class<T> type)
```

So we can create a response for any `String` **term** and declare that we intend
Expand Down Expand Up @@ -300,9 +297,9 @@ the builder call always returns after the _terminal_ call.
- `from(..)` - declares the source for the provided response data elements. It
is declared in a few different ways, for alternative use:

** `from(T... elements)` - vararg elements
** `from(Collection<T> elements)` - provided collection at _build-time_
\*\* `from(Supplier<Iterator<T>> elements)` - supplied iterator at _build-time_
- `from(T... elements)` - vararg elements
- `from(Collection<T> elements)` - provided collection at _build-time_
- `from(Supplier<Iterator<T>> elements)` - supplied iterator at _build-time_

- `suppliedBy(Supplier<Collection<T>> elements)` - declares that response data
is supplied at _run-time_.
Expand All @@ -314,16 +311,16 @@ system using Query/Response across many services. It may tune and change the pro
of resource use, in a network.

```java
responseBuilder.respondTo("offers/monday", Offer.class)
.withBatchesOf(20)
.from(offers.findAllOffersByDayOfWeek(Calendar.MONDAY));
responseBuilder.respondTo("offers/monday", Offer.class)
.withBatchesOf(20)
.from(offers.findAllOffersByDayOfWeek(Calendar.MONDAY));
```

Dynamic responses are easy to build, with an API that suits modern Java, using
lazy calls to suppliers of data.

```java
responseBuilder.respondTo("users/current", Token.class)
.withBatchesOf(128)
.suppliedBy(userTokenService::findAllCurrentUserTokens);
responseBuilder.respondTo("users/current", Token.class)
.withBatchesOf(128)
.suppliedBy(userTokenService::findAllCurrentUserTokens);
```

0 comments on commit 16ef8c5

Please sign in to comment.