{"id":19858631,"url":"https://github.com/nnichols/faker","last_synced_at":"2025-05-02T02:31:07.750Z","repository":{"id":39795500,"uuid":"318537306","full_name":"nnichols/faker","owner":"nnichols","description":"A clojure library for creating fake requests","archived":false,"fork":false,"pushed_at":"2025-04-16T11:25:14.000Z","size":113,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-16T15:13:59.904Z","etag":null,"topics":["clojure","http","testing"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nnichols.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-12-04T14:15:35.000Z","updated_at":"2025-04-16T11:24:50.000Z","dependencies_parsed_at":"2023-02-08T12:31:00.007Z","dependency_job_id":"4aa1ea1d-fa3f-4743-9690-43206f4f8f5f","html_url":"https://github.com/nnichols/faker","commit_stats":{"total_commits":42,"total_committers":1,"mean_commits":42.0,"dds":0.0,"last_synced_commit":"ea82b6655c0c36c05678c58150e6046f3f6ad16d"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnichols%2Ffaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnichols%2Ffaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnichols%2Ffaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnichols%2Ffaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nnichols","download_url":"https://codeload.github.com/nnichols/faker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251972469,"owners_count":21673612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","http","testing"],"created_at":"2024-11-12T14:24:11.068Z","updated_at":"2025-05-02T02:31:04.902Z","avatar_url":"https://github.com/nnichols.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# faker\n\n\u003ca href=\"https://icons8.com/icon/xbZcFKwb9J7z/fraud\"\u003e\u003cimg src=\"resources/icons8-fraud.png\"\u003e\u003c/a\u003e\n[![Clojars Project](https://img.shields.io/clojars/v/nnichols/faker.svg)](https://clojars.org/nnichols/faker)\n[![Dependencies Status](https://versions.deps.co/nnichols/faker/status.svg)](https://versions.deps.co/nnichols/faker)\n[![cljdoc badge](https://cljdoc.org/badge/nnichols/faker)](https://cljdoc.org/d/nnichols/faker/CURRENT)\n![Github Runner](https://github.com/nnichols/faker/workflows/Clojure%20CI/badge.svg)\n\nA Clojure library for generating fake HTTP requests for [Ring](https://github.com/ring-clojure/ring).\n\n\u003e Faker is a negative word, but it's still cool.\n\u003e\n\u003e - Lee \"Faker\" Sang-hyeok from [*SK Telecom T1*](https://en.wikipedia.org/wiki/Faker_(gamer))\n\n## Installation\n\nA deployed copy of the most recent version of [faker can be found on clojars.](https://clojars.org/nnichols/faker)\nTo use it, add the following as a dependency in your `project.clj` file:\n\n[![Clojars Project](http://clojars.org/nnichols/faker/latest-version.svg)](http://clojars.org/nnichols/faker)\n\nThe next time you build your application, [Leiningen](https://leiningen.org/) should pull it automatically.\nAlternatively, you may clone or fork the repository to work with it directly.\n\n## Usage\n\nAll functions necessary to generate requests are provided in the core namespace.\nTo create a fake request, simply specify the HTTP method and resource you'd like to access:\n\n```clojure\n(:require [faker.core :as faker])\n\n(def get-request\n  (faker/mock-request :get \"/v1/resource\"))\n\n;; =\u003e {:protocol \"HTTP/1.1\",\n;;    :server-port 8080,\n;;    :server-name \"localhost\",\n;;    :remote-addr \"127.0.0.1\",\n;;    :uri \"/v1/resource\",\n;;    :scheme :http,\n;;    :request-method :get,\n;;    :headers {\"host\" \"localhost:8080\"}}\n```\n\nThis request is ready to pass directly to your Ring server for testing.\nSince your application's middleware and routes are highly configurable, the `mock-request` function also accepts an optional map to customize the request.\nThe following options are supported:\n\n| Option              | Default Value                  | Description                                                          |\n|---------------------|--------------------------------|----------------------------------------------------------------------|\n| `:protocol`         | `\"HTTP/1.1\"`                   | The HTTP protocol version of the generated request |\n| `:scheme`           | `:http`                        | The URI request scheme to use |\n| `:hostname`         | `\"localhost\"`                  | The hostname to embed in the URI |\n| `:port`             | Inferred based on `:scheme`    | The port number to embed in the URI |\n| `:custom-route?`    | `false`                        | A flag to determine if `resource` should be treated as a fully qualified route. When false, generate a URI from the `scheme`, `hostname`, `port`, and `resource` |\n| `:headers`          | `{}`                           | A map of HTTP headers to add on to the request |\n| `:cookies`          | `{}`                           | A map of HTTP cookies to add on to the request |\n| `:content-type`     | Inferred based on `:body-type` | The HTTP content type the request should be sent with. Defaults to `application/json` for `body-type` :json, `application/xml` for `body-type` :xml, `application/x-www-form-urlencoded` for `body-type` :form. For `body-type` inferred, rely on content-type detection in `ring-mock` |\n| `:content-length`   | Inferred based on `:body`      | The HTTP content length in bytes for the request. If `body-type` != :raw, `ring-mock` will calculate this value for you. |\n| `:body-type`        | `:inferred`                    | The keyword type of content in the request body, which is used to determine how to serialize EDN into the appropriate content-type and to set the `content-type` Expects one of :raw, :xml, :json, :form, :inferred. For :raw, assoc the `body` onto the request as is For :json, serialize the `body` with `cheshire` and set `content-type` to `application/json` For :xml, serialize the `body` with `clojure.data.xml` and set `content-type` to `application/xml` For :form, serialize the `body` as with `ring-mock` and set `content-type` to `application/x-www-form-urlencoded` For :inferred, use the automatic parsing in `ring-mock` and have it set the appropriate `content-type` |\n| `:body`             | `nil`                          | The body of the HTTP request to serialize according to `body-type` |\n| `:query-parameters` | `{}`                           | A map of query parameters to encode and add onto the request. |\n\nFor example:\n\n```clojure\n(faker/mock-request :get \"/\" {:headers   {\"auth\" \"my-secure-token\"}\n                              :body-type :json\n                              :body      {:key 123}\n                              :scheme    :https})\n\n;; =\u003e {:protocol \"HTTP/1.1\",\n;;     :remote-addr \"127.0.0.1\",\n;;     :headers {\"host\" \"localhost:443\", \"content-type\" \"application/json\", \"content-length\" \"11\", \"auth\" \"my-secure-token\"},\n;;     :server-port 443,\n;;     :content-length 11,\n;;     :content-type \"application/json\",\n;;     :uri \"/\",\n;;     :server-name \"localhost\",\n;;     :body #object[java.io.ByteArrayInputStream 0x1f314cee \"java.io.ByteArrayInputStream@1f314cee\"],\n;;     :scheme :https,\n;;     :request-method :get}\n```\n\nSince most applications will use [standard HTTP methods,](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) several aliased versions exist.\nThese functions support the exact same options as `mock-request`\n\n```clojure\n(faker/get \"/\" {:headers   {\"auth\" \"my-secure-token\"}\n                :body-type :json\n                :body      {:key 123}\n                :scheme    :https})\n\n;; =\u003e {:protocol \"HTTP/1.1\",\n;;     :remote-addr \"127.0.0.1\",\n;;     :headers {\"host\" \"localhost:443\", \"content-type\" \"application/json\", \"content-length\" \"11\", \"auth\" \"my-secure-token\"},\n;;     :server-port 443,\n;;     :content-length 11,\n;;     :content-type \"application/json\",\n;;     :uri \"/\",\n;;     :server-name \"localhost\",\n;;     :body #object[java.io.ByteArrayInputStream 0x1f314cee \"java.io.ByteArrayInputStream@1f314cee\"],\n;;     :scheme :https,\n;;     :request-method :get}\n```\n\nCurrently supported methods are:\n\n- `GET`\n- `HEAD`\n- `PUT`\n- `DELETE`\n- `CONNECT`\n- `OPTIONS`\n- `TRACE`\n- `PATCH`\n\nEach of these HTTP methods corresponds 1:1 with a lowercase function name in `faker.core`\n\nThis library currently _does not_ attempt to coerce requests or enforce HTTP standards and best practices on generated requests.\nFor example, you may create a GET request with a body.\nThis can be helpful when writing middleware/handlers for malformed, malicious, or unusual requests.\n\n## Licensing\n\nCopyright © 2020-2022 [Nick Nichols](https://nnichols.github.io/)\n\nDistributed under the [MIT License](https://github.com/nnichols/faker/blob/master/LICENSE)\n\n[Fraud Icon by Icons8](https://icons8.com/icon/xbZcFKwb9J7z/fraud)\n\n### TODO\n\n- Stand up a Ring server in tests, and test normal consumption\n- Support Transit protocol for EDN\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnnichols%2Ffaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnnichols%2Ffaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnnichols%2Ffaker/lists"}