{"id":"6b093dc191bd8fbaf2a0c8cc","slug":"http-request-builder","title":"Budowniczy żądań HTTP","summary":"Płynny budowniczy niezmiennego żądania HTTP – wartości domyślne, normalizacja nagłówków, walidacja w build() i budowniczy wielokrotnego użytku.","servedLang":"pl","availableLangs":["pl","en"],"kind":"code","category":"pattern","status":"published","difficulty":"easy","topics":["builder"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["builder","fluent-interface","immutability","validation","creational"],"languages":[{"lang":"typescript","runner":"browser","starter":"/** Immutable product of the builder. */\nclass HttpRequest {\n  constructor(\n    readonly method: string,\n    readonly url: string,\n    readonly headers: Readonly<Record<string, string>>,\n    readonly body: string | null,\n    readonly timeoutMs: number,\n  ) {\n    // TODO: make the request (and its headers) immutable\n  }\n}\n\n/**\n * Defaults: GET, no headers, no body, 30 000 ms. Every step returns the builder.\n * build() validates (in this order) and throws Error:\n *   'URL must start with http:// or https://', 'Unsupported method: <M>' (GET, POST, PUT, PATCH, DELETE),\n *   '<M> request cannot have a body' (GET, DELETE), 'Timeout must be positive'.\n */\nclass RequestBuilder {\n  constructor(private readonly url: string) {}\n\n  /** Case-insensitive, stored upper-case: 'post' → 'POST'. */\n  method(method: string): this {\n    throw new Error('Not implemented');\n  }\n\n  /** Header names are stored lower-case; the last value wins. */\n  header(name: string, value: string): this {\n    throw new Error('Not implemented');\n  }\n\n  /** Shortcut: header 'authorization' = 'Bearer <token>'. */\n  bearerToken(token: string): this {\n    throw new Error('Not implemented');\n  }\n\n  body(body: string): this {\n    throw new Error('Not implemented');\n  }\n\n  timeout(ms: number): this {\n    throw new Error('Not implemented');\n  }\n\n  build(): HttpRequest {\n    throw new Error('Not implemented');\n  }\n}\n","testCount":8,"tests":"const ORDERS_URL = 'https://api.shop.test/orders';\n\ntest('defaults: GET, no headers, no body, 30 s timeout', () => {\n  const request = new RequestBuilder(ORDERS_URL).build();\n  expect(request).toBeInstanceOf(HttpRequest);\n  expect(request.method).toBe('GET');\n  expect(request.url).toBe(ORDERS_URL);\n  expect(request.headers).toEqual({});\n  expect(request.body).toBeNull();\n  expect(request.timeoutMs).toBe(30000);\n});\n\ntest('every step returns the same builder, so calls chain', () => {\n  const builder = new RequestBuilder(ORDERS_URL);\n  expect(builder.method('post')).toBe(builder);\n  expect(builder.header('Content-Type', 'application/json')).toBe(builder);\n  expect(builder.bearerToken('t0ken')).toBe(builder);\n  expect(builder.body('{\"sku\":\"A1\"}')).toBe(builder);\n  expect(builder.timeout(5000)).toBe(builder);\n  const request = builder.build();\n  expect(request.method).toBe('POST');\n  expect(request.body).toBe('{\"sku\":\"A1\"}');\n  expect(request.timeoutMs).toBe(5000);\n});\n\ntest('header names are case-insensitive and the last value wins', () => {\n  const request = new RequestBuilder(ORDERS_URL)\n    .header('Content-Type', 'text/plain')\n    .header('content-type', 'application/json')\n    .bearerToken('abc')\n    .build();\n  expect(request.headers).toEqual({ 'content-type': 'application/json', authorization: 'Bearer abc' });\n});\n\ntest('the method is normalised and unsupported methods are rejected', () => {\n  expect(new RequestBuilder(ORDERS_URL).method('patch').body('x').build().method).toBe('PATCH');\n  expect(() => new RequestBuilder(ORDERS_URL).method('TRACE').build()).toThrow('Unsupported method: TRACE');\n});\n\ntest('GET and DELETE cannot carry a body', () => {\n  expect(() => new RequestBuilder(ORDERS_URL).body('x').build()).toThrow('GET request cannot have a body');\n  expect(() => new RequestBuilder(ORDERS_URL).method('DELETE').body('x').build()).toThrow('DELETE request cannot have a body');\n  expect(new RequestBuilder(ORDERS_URL).method('PUT').body('x').build().body).toBe('x');\n});\n\ntest('an invalid URL or timeout is rejected by build()', () => {\n  const builder = new RequestBuilder('ftp://files.shop.test');\n  expect(() => builder.timeout(0)).not.toThrow();\n  expect(() => builder.build()).toThrow('URL must start with http:// or https://');\n  expect(() => new RequestBuilder(ORDERS_URL).timeout(0).build()).toThrow('Timeout must be positive');\n  expect(() => new RequestBuilder(ORDERS_URL).timeout(-5).build()).toThrow('Timeout must be positive');\n});\n\ntest('the built request is immutable', () => {\n  const request = new RequestBuilder(ORDERS_URL).method('POST').header('Accept', 'application/json').body('{}').build();\n  expect(() => { request.method = 'DELETE'; }).toThrow();\n  expect(() => { request.headers['x-debug'] = '1'; }).toThrow();\n  expect(request.method).toBe('POST');\n  expect(request.headers).toEqual({ accept: 'application/json' });\n});\n\ntest('a builder can be reused without touching requests already built', () => {\n  const builder = new RequestBuilder(ORDERS_URL).header('Accept', 'application/json');\n  const first = builder.build();\n  builder.header('X-Trace', '42').method('POST').body('{}');\n  const second = builder.build();\n  expect(first).not.toBe(second);\n  expect(first.method).toBe('GET');\n  expect(first.body).toBeNull();\n  expect(first.headers).toEqual({ accept: 'application/json' });\n  expect(second.headers).toEqual({ accept: 'application/json', 'x-trace': '42' });\n});\n"},{"lang":"javascript","runner":"browser","starter":"/** Immutable product of the builder: { method, url, headers, body, timeoutMs }. */\nclass HttpRequest {\n  constructor(method, url, headers, body, timeoutMs) {\n    this.method = method;\n    this.url = url;\n    this.headers = headers;\n    this.body = body;\n    this.timeoutMs = timeoutMs;\n    // TODO: make the request (and its headers) immutable\n  }\n}\n\n/**\n * Defaults: GET, no headers, no body, 30 000 ms. Every step returns the builder.\n * build() validates (in this order) and throws Error:\n *   'URL must start with http:// or https://', 'Unsupported method: <M>' (GET, POST, PUT, PATCH, DELETE),\n *   '<M> request cannot have a body' (GET, DELETE), 'Timeout must be positive'.\n */\nclass RequestBuilder {\n  constructor(url) {\n    this.url = url;\n  }\n\n  /** Case-insensitive, stored upper-case: 'post' → 'POST'. */\n  method(method) {\n    throw new Error('Not implemented');\n  }\n\n  /** Header names are stored lower-case; the last value wins. */\n  header(name, value) {\n    throw new Error('Not implemented');\n  }\n\n  /** Shortcut: header 'authorization' = 'Bearer <token>'. */\n  bearerToken(token) {\n    throw new Error('Not implemented');\n  }\n\n  body(body) {\n    throw new Error('Not implemented');\n  }\n\n  timeout(ms) {\n    throw new Error('Not implemented');\n  }\n\n  build() {\n    throw new Error('Not implemented');\n  }\n}\n","testCount":8,"tests":"const ORDERS_URL = 'https://api.shop.test/orders';\n\ntest('defaults: GET, no headers, no body, 30 s timeout', () => {\n  const request = new RequestBuilder(ORDERS_URL).build();\n  expect(request).toBeInstanceOf(HttpRequest);\n  expect(request.method).toBe('GET');\n  expect(request.url).toBe(ORDERS_URL);\n  expect(request.headers).toEqual({});\n  expect(request.body).toBeNull();\n  expect(request.timeoutMs).toBe(30000);\n});\n\ntest('every step returns the same builder, so calls chain', () => {\n  const builder = new RequestBuilder(ORDERS_URL);\n  expect(builder.method('post')).toBe(builder);\n  expect(builder.header('Content-Type', 'application/json')).toBe(builder);\n  expect(builder.bearerToken('t0ken')).toBe(builder);\n  expect(builder.body('{\"sku\":\"A1\"}')).toBe(builder);\n  expect(builder.timeout(5000)).toBe(builder);\n  const request = builder.build();\n  expect(request.method).toBe('POST');\n  expect(request.body).toBe('{\"sku\":\"A1\"}');\n  expect(request.timeoutMs).toBe(5000);\n});\n\ntest('header names are case-insensitive and the last value wins', () => {\n  const request = new RequestBuilder(ORDERS_URL)\n    .header('Content-Type', 'text/plain')\n    .header('content-type', 'application/json')\n    .bearerToken('abc')\n    .build();\n  expect(request.headers).toEqual({ 'content-type': 'application/json', authorization: 'Bearer abc' });\n});\n\ntest('the method is normalised and unsupported methods are rejected', () => {\n  expect(new RequestBuilder(ORDERS_URL).method('patch').body('x').build().method).toBe('PATCH');\n  expect(() => new RequestBuilder(ORDERS_URL).method('TRACE').build()).toThrow('Unsupported method: TRACE');\n});\n\ntest('GET and DELETE cannot carry a body', () => {\n  expect(() => new RequestBuilder(ORDERS_URL).body('x').build()).toThrow('GET request cannot have a body');\n  expect(() => new RequestBuilder(ORDERS_URL).method('DELETE').body('x').build()).toThrow('DELETE request cannot have a body');\n  expect(new RequestBuilder(ORDERS_URL).method('PUT').body('x').build().body).toBe('x');\n});\n\ntest('an invalid URL or timeout is rejected by build()', () => {\n  const builder = new RequestBuilder('ftp://files.shop.test');\n  expect(() => builder.timeout(0)).not.toThrow();\n  expect(() => builder.build()).toThrow('URL must start with http:// or https://');\n  expect(() => new RequestBuilder(ORDERS_URL).timeout(0).build()).toThrow('Timeout must be positive');\n  expect(() => new RequestBuilder(ORDERS_URL).timeout(-5).build()).toThrow('Timeout must be positive');\n});\n\ntest('the built request is immutable', () => {\n  const request = new RequestBuilder(ORDERS_URL).method('POST').header('Accept', 'application/json').body('{}').build();\n  expect(() => { request.method = 'DELETE'; }).toThrow();\n  expect(() => { request.headers['x-debug'] = '1'; }).toThrow();\n  expect(request.method).toBe('POST');\n  expect(request.headers).toEqual({ accept: 'application/json' });\n});\n\ntest('a builder can be reused without touching requests already built', () => {\n  const builder = new RequestBuilder(ORDERS_URL).header('Accept', 'application/json');\n  const first = builder.build();\n  builder.header('X-Trace', '42').method('POST').body('{}');\n  const second = builder.build();\n  expect(first).not.toBe(second);\n  expect(first.method).toBe('GET');\n  expect(first.body).toBeNull();\n  expect(first.headers).toEqual({ accept: 'application/json' });\n  expect(second.headers).toEqual({ accept: 'application/json', 'x-trace': '42' });\n});\n"},{"lang":"python","runner":"browser","starter":"from dataclasses import dataclass\nfrom typing import Mapping\n\n\n@dataclass(frozen=True)\nclass HttpRequest:\n    \"\"\"Immutable product of the builder (headers must be read-only too).\"\"\"\n\n    method: str\n    url: str\n    headers: Mapping[str, str]\n    body: str | None\n    timeout_ms: int\n\n\nclass RequestBuilder:\n    \"\"\"Defaults: GET, no headers, no body, 30 000 ms. Every step returns the builder.\n    build() validates (in this order) and raises ValueError:\n      'URL must start with http:// or https://', 'Unsupported method: <M>' (GET, POST, PUT, PATCH, DELETE),\n      '<M> request cannot have a body' (GET, DELETE), 'Timeout must be positive'.\"\"\"\n\n    def __init__(self, url: str):\n        self._url = url\n\n    def method(self, method: str) -> \"RequestBuilder\":\n        \"\"\"Case-insensitive, stored upper-case: 'post' → 'POST'.\"\"\"\n        raise NotImplementedError\n\n    def header(self, name: str, value: str) -> \"RequestBuilder\":\n        \"\"\"Header names are stored lower-case; the last value wins.\"\"\"\n        raise NotImplementedError\n\n    def bearer_token(self, token: str) -> \"RequestBuilder\":\n        \"\"\"Shortcut: header 'authorization' = 'Bearer <token>'.\"\"\"\n        raise NotImplementedError\n\n    def body(self, body: str) -> \"RequestBuilder\":\n        raise NotImplementedError\n\n    def timeout(self, ms: int) -> \"RequestBuilder\":\n        raise NotImplementedError\n\n    def build(self) -> HttpRequest:\n        raise NotImplementedError\n","testCount":8,"tests":"ORDERS_URL = \"https://api.shop.test/orders\"\n\n\ndef test_defaults_get_no_headers_no_body_30_s_timeout():\n    request = RequestBuilder(ORDERS_URL).build()\n    assert isinstance(request, HttpRequest)\n    assert request.method == \"GET\", f\"got {request.method}\"\n    assert request.url == ORDERS_URL\n    assert dict(request.headers) == {}, f\"got {dict(request.headers)}\"\n    assert request.body is None\n    assert request.timeout_ms == 30000, f\"got {request.timeout_ms}\"\n\n\ndef test_every_step_returns_the_same_builder_so_calls_chain():\n    builder = RequestBuilder(ORDERS_URL)\n    assert builder.method(\"post\") is builder\n    assert builder.header(\"Content-Type\", \"application/json\") is builder\n    assert builder.bearer_token(\"t0ken\") is builder\n    assert builder.body('{\"sku\":\"A1\"}') is builder\n    assert builder.timeout(5000) is builder\n    request = builder.build()\n    assert request.method == \"POST\"\n    assert request.body == '{\"sku\":\"A1\"}'\n    assert request.timeout_ms == 5000\n\n\ndef test_header_names_are_case_insensitive_and_the_last_value_wins():\n    request = (RequestBuilder(ORDERS_URL)\n               .header(\"Content-Type\", \"text/plain\")\n               .header(\"content-type\", \"application/json\")\n               .bearer_token(\"abc\")\n               .build())\n    got = dict(request.headers)\n    assert got == {\"content-type\": \"application/json\", \"authorization\": \"Bearer abc\"}, f\"got {got}\"\n\n\ndef test_the_method_is_normalised_and_unsupported_methods_are_rejected():\n    assert RequestBuilder(ORDERS_URL).method(\"patch\").body(\"x\").build().method == \"PATCH\"\n    with raises(ValueError, match=\"Unsupported method: TRACE\"):\n        RequestBuilder(ORDERS_URL).method(\"TRACE\").build()\n\n\ndef test_get_and_delete_cannot_carry_a_body():\n    with raises(ValueError, match=\"GET request cannot have a body\"):\n        RequestBuilder(ORDERS_URL).body(\"x\").build()\n    with raises(ValueError, match=\"DELETE request cannot have a body\"):\n        RequestBuilder(ORDERS_URL).method(\"DELETE\").body(\"x\").build()\n    assert RequestBuilder(ORDERS_URL).method(\"PUT\").body(\"x\").build().body == \"x\"\n\n\ndef test_an_invalid_url_or_timeout_is_rejected_by_build():\n    builder = RequestBuilder(\"ftp://files.shop.test\")\n    builder.timeout(0)  # no exception yet – validation happens in build()\n    with raises(ValueError, match=\"URL must start with http:// or https://\"):\n        builder.build()\n    with raises(ValueError, match=\"Timeout must be positive\"):\n        RequestBuilder(ORDERS_URL).timeout(0).build()\n    with raises(ValueError, match=\"Timeout must be positive\"):\n        RequestBuilder(ORDERS_URL).timeout(-5).build()\n\n\ndef test_the_built_request_is_immutable():\n    request = RequestBuilder(ORDERS_URL).method(\"POST\").header(\"Accept\", \"application/json\").body(\"{}\").build()\n    with raises(AttributeError):\n        request.method = \"DELETE\"\n    with raises(TypeError):\n        request.headers[\"x-debug\"] = \"1\"\n    assert request.method == \"POST\"\n    assert dict(request.headers) == {\"accept\": \"application/json\"}\n\n\ndef test_a_builder_can_be_reused_without_touching_requests_already_built():\n    builder = RequestBuilder(ORDERS_URL).header(\"Accept\", \"application/json\")\n    first = builder.build()\n    builder.header(\"X-Trace\", \"42\").method(\"POST\").body(\"{}\")\n    second = builder.build()\n    assert first is not second\n    assert first.method == \"GET\" and first.body is None\n    assert dict(first.headers) == {\"accept\": \"application/json\"}, f\"got {dict(first.headers)}\"\n    assert dict(second.headers) == {\"accept\": \"application/json\", \"x-trace\": \"42\"}\n"},{"lang":"csharp","runner":"judge0","starter":"using System;\nusing System.Collections.Generic;\nusing System.Collections.ObjectModel;\n\n/// <summary>Immutable product of the builder: get-only properties, read-only headers.</summary>\npublic sealed class HttpRequest\n{\n    internal HttpRequest(string method, string url, IReadOnlyDictionary<string, string> headers, string body, TimeSpan timeout)\n    {\n        Method = method;\n        Url = url;\n        Headers = headers;\n        Body = body;\n        Timeout = timeout;\n    }\n\n    public string Method { get; }\n    public string Url { get; }\n    public IReadOnlyDictionary<string, string> Headers { get; }\n    public string Body { get; }      // null = no body\n    public TimeSpan Timeout { get; }\n}\n\n/// <summary>\n/// Defaults: GET, no headers, no body, 30 s. Every step returns the builder.\n/// Build() validates (in this order) and throws InvalidOperationException:\n///   \"URL must start with http:// or https://\", \"Unsupported method: M\" (GET, POST, PUT, PATCH, DELETE),\n///   \"M request cannot have a body\" (GET, DELETE), \"Timeout must be positive\".\n/// </summary>\npublic sealed class HttpRequestBuilder\n{\n    private readonly string url;\n\n    public HttpRequestBuilder(string url)\n    {\n        this.url = url;\n    }\n\n    /// <summary>Case-insensitive, stored upper-case: \"post\" → \"POST\".</summary>\n    public HttpRequestBuilder Method(string method) { throw new NotImplementedException(); }\n\n    /// <summary>Header names are stored lower-case; the last value wins.</summary>\n    public HttpRequestBuilder Header(string name, string value) { throw new NotImplementedException(); }\n\n    /// <summary>Shortcut: header \"authorization\" = \"Bearer token\".</summary>\n    public HttpRequestBuilder BearerToken(string token) { throw new NotImplementedException(); }\n\n    public HttpRequestBuilder Body(string body) { throw new NotImplementedException(); }\n\n    public HttpRequestBuilder Timeout(TimeSpan timeout) { throw new NotImplementedException(); }\n\n    public HttpRequest Build() { throw new NotImplementedException(); }\n}\n","testCount":8},{"lang":"java","runner":"judge0","starter":"import java.util.Map;\nimport java.util.Optional;\n\n/** Immutable product of the builder; created only through HttpRequest.builder(url). */\nfinal class HttpRequest {\n    private final String method;\n    private final String url;\n    private final Map<String, String> headers;\n    private final String body;\n    private final long timeoutMillis;\n\n    private HttpRequest(Builder b) {\n        // TODO: copy the builder's state (headers as an unmodifiable copy)\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n\n    static Builder builder(String url) { return new Builder(url); }\n\n    String method() { return method; }\n    String url() { return url; }\n    Map<String, String> headers() { return headers; }\n    Optional<String> body() { return Optional.ofNullable(body); }\n    long timeoutMillis() { return timeoutMillis; }\n\n    /**\n     * Defaults: GET, no headers, no body, 30 000 ms. Every step returns the builder.\n     * build() validates (in this order) and throws IllegalStateException:\n     *   \"URL must start with http:// or https://\", \"Unsupported method: M\" (GET, POST, PUT, PATCH, DELETE),\n     *   \"M request cannot have a body\" (GET, DELETE), \"Timeout must be positive\".\n     */\n    static final class Builder {\n        private final String url;\n\n        private Builder(String url) { this.url = url; }\n\n        /** Case-insensitive, stored upper-case: \"post\" → \"POST\". */\n        Builder method(String method) { throw new UnsupportedOperationException(\"Not implemented\"); }\n\n        /** Header names are stored lower-case; the last value wins. */\n        Builder header(String name, String value) { throw new UnsupportedOperationException(\"Not implemented\"); }\n\n        /** Shortcut: header \"authorization\" = \"Bearer token\". */\n        Builder bearerToken(String token) { throw new UnsupportedOperationException(\"Not implemented\"); }\n\n        Builder body(String body) { throw new UnsupportedOperationException(\"Not implemented\"); }\n\n        Builder timeoutMillis(long millis) { throw new UnsupportedOperationException(\"Not implemented\"); }\n\n        HttpRequest build() { throw new UnsupportedOperationException(\"Not implemented\"); }\n    }\n}\n","testCount":8},{"lang":"go","runner":"judge0","starter":"package main\n\nimport \"time\"\n\n// Request is the immutable product of the builder: unexported fields, read through methods.\ntype Request struct {\n\tmethod  string\n\turl     string\n\theaders map[string]string\n\tbody    string\n\ttimeout time.Duration\n}\n\n// Method, URL, Body and Timeout are read-only accessors.\nfunc (r *Request) Method() string         { return r.method }\nfunc (r *Request) URL() string            { return r.url }\nfunc (r *Request) Body() string           { return r.body }\nfunc (r *Request) Timeout() time.Duration { return r.timeout }\n\n// Header returns the value of a header (names are case-insensitive), \"\" when missing.\nfunc (r *Request) Header(name string) string {\n\t// TODO\n\treturn \"\"\n}\n\n// Headers returns a copy – changing it must not change the request.\nfunc (r *Request) Headers() map[string]string {\n\t// TODO\n\treturn nil\n}\n\n// RequestBuilder: defaults GET, no headers, no body (\"\"), 30 s. Every step returns the builder.\n// Build validates (in this order): \"url must start with http:// or https://\",\n// \"unsupported method: M\" (GET, POST, PUT, PATCH, DELETE), \"M request cannot have a body\" (GET, DELETE),\n// \"timeout must be positive\".\ntype RequestBuilder struct {\n\turl string\n\t// TODO: method, headers, body, timeout\n}\n\n// NewRequestBuilder starts a request for url.\nfunc NewRequestBuilder(url string) *RequestBuilder {\n\treturn &RequestBuilder{url: url}\n}\n\n// Method is case-insensitive and stored upper-case: \"post\" → \"POST\".\nfunc (b *RequestBuilder) Method(method string) *RequestBuilder { return b } // TODO\n\n// Header names are stored lower-case; the last value wins.\nfunc (b *RequestBuilder) Header(name, value string) *RequestBuilder { return b } // TODO\n\n// BearerToken sets the header \"authorization\" to \"Bearer <token>\".\nfunc (b *RequestBuilder) BearerToken(token string) *RequestBuilder { return b } // TODO\n\n// Body sets the request body.\nfunc (b *RequestBuilder) Body(body string) *RequestBuilder { return b } // TODO\n\n// Timeout sets the request timeout.\nfunc (b *RequestBuilder) Timeout(d time.Duration) *RequestBuilder { return b } // TODO\n\n// Build validates the state and creates a new, independent Request.\nfunc (b *RequestBuilder) Build() (*Request, error) {\n\t// TODO\n\treturn &Request{}, nil\n}\n","testCount":8}],"questionCount":null,"xp":10,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:25.386Z","requestedLang":"pl","statement":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Klient HTTP w sklepie ma konstruktor z sześcioma parametrami, z czego połowa bywa "},{"type":"text","text":"null","marks":[{"type":"code"}]},{"type":"text","text":": "},{"type":"text","text":"new HttpRequest('POST', url, null, body, null, 5000)","marks":[{"type":"code"}]},{"type":"text","text":". Nikt nie pamięta kolejności, a błędne kombinacje (GET z treścią, ujemny limit czasu) wychodzą dopiero na produkcji. "},{"type":"text","text":"Budowniczy","marks":[{"type":"bold"}]},{"type":"text","text":" (ang. "},{"type":"text","text":"Builder","marks":[{"type":"italic"}]},{"type":"text","text":") rozdziela składanie obiektu krok po kroku od jego wyniku: kod czyta się jak zdanie, a gotowe żądanie jest "},{"type":"text","text":"niezmienne","marks":[{"type":"bold"}]},{"type":"text","text":" i zawsze poprawne."}]},{"type":"heading","attrs":{"level":2,"id":"zadanie"},"content":[{"type":"text","text":"Zadanie"}]},{"type":"orderedList","attrs":{"start":1},"content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Budowniczy","marks":[{"type":"bold"}]},{"type":"text","text":" ("},{"type":"text","text":"RequestBuilder(url)","marks":[{"type":"code"}]},{"type":"text","text":"; w Javie "},{"type":"text","text":"HttpRequest.builder(url)","marks":[{"type":"code"}]},{"type":"text","text":") ma wartości domyślne: metoda "},{"type":"text","text":"GET","marks":[{"type":"code"}]},{"type":"text","text":", brak nagłówków, brak treści, limit czasu 30 s. Każdy krok zwraca "},{"type":"text","text":"tego samego","marks":[{"type":"bold"}]},{"type":"text","text":" budowniczego:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"method(m)","marks":[{"type":"code"}]},{"type":"text","text":" – bez względu na wielkość liter, zapisywana wielkimi ("},{"type":"text","text":"post","marks":[{"type":"code"}]},{"type":"text","text":" → "},{"type":"text","text":"POST","marks":[{"type":"code"}]},{"type":"text","text":");"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"header(name, value)","marks":[{"type":"code"}]},{"type":"text","text":" – nazwy zapisywane małymi literami, ostatnia wartość wygrywa;"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"bearerToken(token)","marks":[{"type":"code"}]},{"type":"text","text":" – skrót do nagłówka "},{"type":"text","text":"authorization: Bearer <token>","marks":[{"type":"code"}]},{"type":"text","text":";"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"body(text)","marks":[{"type":"code"}]},{"type":"text","text":" i "},{"type":"text","text":"timeout(...)","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"build()","marks":[{"type":"code"}]},{"type":"text","text":" sprawdza stan w tej kolejności i zgłasza błąd z komunikatem:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"URL must start with http:// or https://","marks":[{"type":"code"}]},{"type":"text","text":","}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Unsupported method: <M>","marks":[{"type":"code"}]},{"type":"text","text":" (dozwolone "},{"type":"text","text":"GET","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"POST","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"PUT","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"PATCH","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"DELETE","marks":[{"type":"code"}]},{"type":"text","text":"),"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"<M> request cannot have a body","marks":[{"type":"code"}]},{"type":"text","text":" (dla "},{"type":"text","text":"GET","marks":[{"type":"code"}]},{"type":"text","text":" i "},{"type":"text","text":"DELETE","marks":[{"type":"code"}]},{"type":"text","text":"),"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Timeout must be positive","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Same kroki budowniczego niczego nie walidują – błąd pojawia się dopiero w "},{"type":"text","text":"build()","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Wynik jest niezmienny","marks":[{"type":"bold"}]},{"type":"text","text":": nie da się zmienić pól ani nagłówków gotowego żądania, a dalsze wywołania na budowniczym nie wpływają na żądania zbudowane wcześniej. Każde "},{"type":"text","text":"build()","marks":[{"type":"code"}]},{"type":"text","text":" tworzy nowy obiekt."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Szczegóły językowe: TypeScript/JavaScript – "},{"type":"text","text":"Object.freeze","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"timeout(ms)","marks":[{"type":"code"}]},{"type":"text","text":", błąd "},{"type":"text","text":"Error","marks":[{"type":"code"}]},{"type":"text","text":"; Python – "},{"type":"text","text":"@dataclass(frozen=True)","marks":[{"type":"code"}]},{"type":"text","text":", nagłówki jako "},{"type":"text","text":"MappingProxyType","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"bearer_token","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"ValueError","marks":[{"type":"code"}]},{"type":"text","text":"; C# – "},{"type":"text","text":"IReadOnlyDictionary","marks":[{"type":"code"}]},{"type":"text","text":" (np. "},{"type":"text","text":"ReadOnlyDictionary","marks":[{"type":"code"}]},{"type":"text","text":"), "},{"type":"text","text":"Timeout(TimeSpan)","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"InvalidOperationException","marks":[{"type":"code"}]},{"type":"text","text":"; Java – statyczna klasa zagnieżdżona "},{"type":"text","text":"HttpRequest.Builder","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Collections.unmodifiableMap","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"body()","marks":[{"type":"code"}]},{"type":"text","text":" zwraca "},{"type":"text","text":"Optional<String>","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"IllegalStateException","marks":[{"type":"code"}]},{"type":"text","text":"; Go – nieeksportowane pola z metodami dostępowymi, "},{"type":"text","text":"Headers()","marks":[{"type":"code"}]},{"type":"text","text":" zwraca kopię, "},{"type":"text","text":"Build() (*Request, error)","marks":[{"type":"code"}]},{"type":"text","text":", komunikaty błędów małą literą zgodnie z konwencją Go ("},{"type":"text","text":"url must start with…","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"timeout must be positive","marks":[{"type":"code"}]},{"type":"text","text":")."}]}]},"hints":[],"hintsCount":3,"quiz":null,"solutionNotes":null,"unlocked":false,"external":[],"articles":[{"id":"6b08bd2f80884893657cc8f2","slug":"builder","title":"Budowniczy (Builder) – złożone obiekty krok po kroku"}],"topicsInfo":[{"slug":"builder","title":"Budowniczy","group":"creational","icon":"hammer"}],"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"capabilities":{"judge0":false,"aiReview":false},"createdAt":"2026-11-27T08:22:25.388Z","updatedAt":"2026-11-27T08:22:25.388Z"}