NeoFaker.Http (neo_faker v0.11.0)

View Source

Functions for generating HTTP-related information.

This module provides utilities to generate random internet-related information, such request methods, status codes, and user-agents.

Summary

Functions

Generates a random HTTP referrer policy.

Generates a random HTTP request method.

Generates a random HTTP status code string.

Generates a random HTTP user-agent string.

Functions

referrer_policy()

(since 0.11.0)
@spec referrer_policy() :: String.t()

Generates a random HTTP referrer policy.

Returns a random HTTP referrer policy string.

Examples

iex> NeoFaker.Http.referrer_policy()
"no-referrer"

request_method()

(since 0.11.0)
@spec request_method() :: String.t()

Generates a random HTTP request method.

Returns a random HTTP request method string.

Examples

iex> NeoFaker.Http.request_method()
"GET"

status_code(opts \\ [])

(since 0.11.0)
@spec status_code(Keyword.t()) :: String.t()

Generates a random HTTP status code string.

Returns a random HTTP status code string, which can be either detailed (e.g., "200 OK") or simple (e.g., "200").

Options

The accepted options are:

  • :type - Defines the type of status code to generate.
  • :group - Specifies the group of status codes to generate.

The values for :type can be:

  • :detailed - Returns a detailed status code (e.g., "200 OK"), which is the default.
  • :simple - Returns a simple status code (e.g., "200" instead of "200 OK").

The values for :group can be:

  • nil - All status codes (default).
  • :information - 1xx status codes (Informational).
  • :success - 2xx status codes (Success).
  • :redirection - 3xx status codes (Redirection).
  • :client_error - 4xx status codes (Client Error).
  • :server_error - 5xx status codes (Server Error).

Examples

iex> NeoFaker.Http.status_code()
"200 OK"

iex> NeoFaker.Http.status_code(type: :simple)
"200"

iex> NeoFaker.Http.status_code(group: :client_error)
"404 Not Found"

user_agent(opts \\ [])

(since 0.11.0)
@spec user_agent(Keyword.t()) :: String.t()

Generates a random HTTP user-agent string.

Selects a user-agent from a curated list of the top 100 most common HTTP user-agents, with optional filtering by type.

Options

The accepted options are:

  • :type - Defines the type of user-agent to generate.

The values for :type can be:

  • :all - Returns a random user-agent from both browsers and crawlers (default).
  • :browser - Returns a random browser user-agent.
  • :crawler - Returns a random crawler user-agent.

Examples

iex> NeoFaker.Internet.user_agent()
"Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0"

iex> NeoFaker.Internet.user_agent(type: :browser)
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0"

iex> NeoFaker.Internet.user_agent(type: :crawler)
"Mozilla/5.0 (compatible; Google-InspectionTool/1.0)"