304 Means Cached
Your extension polls a trading partner's price feed every two minutes, and the payload — a few hundred kilobytes of catalog prices — changes maybe twice a day. Last month the partner's ops team sent a polite email with an impolite traffic graph: your tenant downloaded the identical payload eleven thousand times. HTTP solved this decades ago: the server stamps every payload with an ETag, a well-behaved client echoes it back in If-None-Match, and the server answers a bodyless 304 Not Modified when nothing changed. You are building that well-behaved client: a reader that remembers the last ETag and payload per URL, revalidates instead of re-downloading, and only pays for the bytes when they actually changed.
The grading container has no outbound network, so the reader never talks HTTP itself: it fetches through a small seam — an interface whose production implementation would wrap HttpClient, and whose grading implementation is a mock origin server the tests control.
Requirements
Create an interface named "Http Get Backend" with exactly this declaration:
interface "Http Get Backend"
{
procedure Get(Url: Text; IfNoneMatch: Text; var StatusCode: Integer; var Etag: Text; var Body: Text)
}Get performs one HTTP GET against Url. IfNoneMatch is the value of the If-None-Match request header; pass empty text when the header must not be sent. The response comes back through the var parameters: the HTTP status code, the value of the ETag response header (empty when the response carried none) and the response body.
Then create a codeunit named "Cached Http Reader" with two public procedures:
procedure SetBackend(NewBackend: Interface "Http Get Backend")
procedure GetResource(Url: Text): TextSolve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 12 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
Already on Pro? Sign in