### Install and Run httpbin with Python and Gunicorn
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/httpbin.1.html
Provides instructions for installing the httpbin Python library from PyPI and running it as a WSGI application using Gunicorn. This setup allows for local hosting and testing of the httpbin service.
```bash
$ pip install httpbin
$ gunicorn httpbin:app
```
--------------------------------
### Basic HTTP Request Examples with Curl
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/httpbin.1.html
Demonstrates common HTTP requests using the `curl` command-line tool against httpbin.org. Examples include retrieving client IP, user-agent, full GET request details, inspecting HTTP status codes and headers, and handling query parameters.
```bash
$ curl http://httpbin.org/ip
{"origin": "24.127.96.129"}
```
```bash
$ curl http://httpbin.org/user-agent
{"user-agent": "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3"}
```
```bash
$ curl http://httpbin.org/get
{
"args": {},
"headers": {
"Accept": "*/*",
"Connection": "close",
"Content-Length": "",
"Content-Type": "",
"Host": "httpbin.org",
"User-Agent": "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3"
},
"origin": "24.127.96.129",
"url": "http://httpbin.org/get"
}
```
```bash
$ curl -I http://httpbin.org/status/418
HTTP/1.1 418 I'M A TEAPOT
Server: nginx/0.7.67
Date: Mon, 13 Jun 2011 04:25:38 GMT
Connection: close
x-more-info: http://tools.ietf.org/html/rfc2324
Content-Length: 135
```
```bash
$ curl https://httpbin.org/get?show_env=1
{
"headers": {
"Content-Length": "",
"Accept-Language": "en-US,en;q=0.8",
"Accept-Encoding": "gzip,deflate,sdch",
"X-Forwarded-Port": "443",
"X-Forwarded-For": "109.60.101.240",
"Host": "httpbin.org",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"User-Agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.83 Safari/535.11",
"X-Request-Start": "1350053933441",
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
"Connection": "keep-alive",
"X-Forwarded-Proto": "https",
"Cookie": "_gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1; _gauges_unique_hour=1",
"Content-Type": ""
},
"args": {
"show_env": "1"
},
"origin": "109.60.101.240",
"url": "http://httpbin.org/get?show_env=1"
}
```
--------------------------------
### Basic CSS Styling for HTML Elements
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/flasgger/index.html
This CSS snippet defines basic box-sizing, overflow behavior, and body margin/background for an HTML page, ensuring consistent layout and appearance.
```CSS
html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; } *, *:before, *:after { box-sizing: inherit; } body { margin: 0; background: #fafafa; }
```
--------------------------------
### Run httpbin Locally with Docker
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/flasgger/index.html
This command runs the httpbin service locally using Docker, mapping port 80 of the container to port 80 on the host machine. It uses the `kennethreitz/httpbin` Docker image.
```Shell
$ docker run -p 80:80 kennethreitz/httpbin
```
--------------------------------
### Initialize Swagger UI with Dynamic Configuration and JWT Interceptors
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/flasgger/index.html
This JavaScript code, enhanced with Jinja2 templating, initializes Swagger UI dynamically on page load. It fetches OpenAPI specifications, adjusts the protocol and host to match the current environment, and configures Swagger UI with deep linking, JSON editor, and alphabetical sorting. Optionally, it includes request and response interceptors for handling JWT tokens if `JWT_AUTH_URL_RULE` is enabled in the configuration.
```JavaScript
window.onload = function () {
{% if config.JWT_AUTH_URL_RULE %}
// JWT token holder
var jwt_token;
{% endif %}
fetch("{{ specs[0]['url'] }}")
.then(function (response) {
response.json()
.then(function (json) {
var current_protocol = window.location.protocol.slice(0, -1);
if (json.schemes[0] != current_protocol) {
// Switches scheme to the current in use
var other_protocol = json.schemes[0];
json.schemes[0] = current_protocol;
json.schemes[1] = other_protocol;
}
json.host = window.location.host; // sets the current host
const ui = SwaggerUIBundle({
spec: json,
validatorUrl: null,
dom_id: '#swagger-ui',
deepLinking: true,
jsonEditor: true,
docExpansion: "none",
apisSorter: "alpha",
//operationsSorter: "alpha",
presets: [
SwaggerUIBundle.presets.apis,
// yay ES6 modules ↘
Array.isArray(SwaggerUIStandalonePreset) ? SwaggerUIStandalonePreset : SwaggerUIStandalonePreset.default
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
{% if config.JWT_AUTH_URL_RULE %}
requestInterceptor: function (request) {
if (jwt_token) {
request.headers.Authorization = "Bearer " + jwt_token;
}
return request;
},
responseInterceptor: function (response) {
var tokenField = 'jwt-token';
var headers = response.headers;
if (headers.hasOwnProperty(tokenField)) {
jwt_token = headers[tokenField];
}
return response;
},
{% endif %}
// layout: "StandaloneLayout"
// uncomment to enable the green top header
})
window.ui = ui
// uncomment to rename the top brand if layout is enabled
// $(".topbar-wrapper .link span").replaceWith("httpbin");
})
})
}
{% if tracking_enabled %}
{% include 'trackingscripts.html' %}
{% endif %}
{% include 'footer.html' %}
```
--------------------------------
### UTF-8 Encoded Unicode Character Demonstration
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/UTF-8-demo.txt
This snippet presents a sample plain-text file encoded in UTF-8, illustrating the representation of a broad spectrum of Unicode characters. It includes examples of mathematical and scientific notation, phonetic symbols, APL characters, advanced typographic elements (quotes, dashes, currency symbols), and text in multiple languages such as Greek (Polytonic), Georgian, Russian, and Thai. This demonstrates the robustness of UTF-8 for internationalization.
```Plain Text (UTF-8)
UTF-8 encoded sample plain-text file
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Markus Kuhn [ˈmaʳkʊs kuːn] — 2002-07-25
The ASCII compatible UTF-8 encoding used in this plain-text file
is defined in Unicode, ISO 10646-1, and RFC 2279.
Using Unicode/UTF-8, you can write in emails and source code things such as
Mathematics and sciences:
∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i), ⎧⎡⎛┌─────┐⎞⎤⎫
⎪⎢⎜│a²+b³ ⎟⎥⎪
∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β), ⎪⎢⎜│───── ⎟⎥⎪
⎪⎢⎜⎷ c₈ ⎟⎥⎪
ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⎨⎢⎜ ⎟⎥⎬
⎪⎢⎜ ∞ ⎟⎥⎪
⊥ < a ≠ b ≡ c ≤ d ≪ ⊤ ⇒ (⟦A⟧ ⇔ ⟪B⟫), ⎪⎢⎜ ⎲ ⎟⎥⎪
⎪⎢⎜ ⎳aⁱ-bⁱ⎟⎥⎪
2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm ⎩⎣⎝i=1 ⎠⎦⎭
Linguistics and dictionaries:
ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn
Y [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]
APL:
((V⍳V)=⍳⍴V)/V←,V ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈
Nicer typography in plain text files:
╔══════════════════════════════════════════╗
║ ║
║ • ‘single’ and “double” quotes ║
║ ║
║ • Curly apostrophes: “We’ve been here” ║
║ ║
║ • Latin-1 apostrophe and accents: '´` ║
║ ║
║ • ‚deutsche‘ „Anführungszeichen“ ║
║ ║
║ • †, ‡, ‰, •, 3–4, —, −5/+5, ™, … ║
║ ║
║ • ASCII safety test: 1lI|, 0OD, 8B ║
║ ╭─────────╮ ║
║ • the euro symbol: │ 14.95 € │ ║
║ ╰─────────╯ ║
╚══════════════════════════════════════════╝
Combining characters:
STARGΛ̊TE SG-1, a = v̇ = r̈, a⃑ ⊥ b⃑
Greek (in Polytonic):
The Greek anthem:
Σὲ γνωρίζω ἀπὸ τὴν κόψη
τοῦ σπαθιοῦ τὴν τρομερή,
σὲ γνωρίζω ἀπὸ τὴν ὄψη
ποὺ μὲ βία μετράει τὴ γῆ.
᾿Απ᾿ τὰ κόκκαλα βγαλμένη
τῶν ῾Ελλήνων τὰ ἱερά
καὶ σὰν πρῶτα ἀνδρειωμένη
χαῖρε, ὦ χαῖρε, ᾿Ελευθεριά!
From a speech of Demosthenes in the 4th century BC:
Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
εἰς τοῦτο προήκοντα, ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
πρότερον κακῶς σκέψασθαι δέον. οὐδέν οὖν ἄλλο μοι δοκοῦσιν
οἱ τὰ τοιαῦτα λέγοντες ἢ τὴν ὑπόθεσιν, περὶ ἧς βουλεύεσθαι,
οὐχὶ τὴν οὖσαν παριστάντες ὑμῖν ἁμαρτάνειν. ἐγὼ δέ, ὅτι μέν
ποτ᾿ ἐξῆν τῇ πόλει καὶ τὰ αὑτῆς ἔχειν ἀσφαλῶς καὶ Φίλιππον
τιμωρήσασθαι, καὶ μάλ᾿ ἀκριβῶς οἶδα· ἐπ᾿ ἐμοῦ γάρ, οὐ πάλαι
γέγονεν ταῦτ᾿ ἀμφότερα· νῦν μέντοι πέπεισμαι τοῦθ᾿ ἱκανὸν
προλαβεῖν ἡμῖν εἶναι τὴν πρώτην, ὅπως τοὺς συμμάχους
σώσομεν. ἐὰν γὰρ τοῦτο βεβαίως ὑπάρξῃ, τότε καὶ περὶ τοῦ
τίνα τιμωρήσεταί τις καὶ ὃν τρόπον ἐξέσται σκοπεῖν· πρὶν δὲ
τὴν ἀρχὴν ὀρθῶς ὑποθέσθαι, μάταιον ἡγοῦμαι περὶ τῆς
τελευτῆς ὁντινοῦν ποιεῖσθαι λόγον.
Δημοσθένους, Γ´ ᾿Ολυνθιακὸς
Georgian:
From a Unicode conference invitation:
გთხოვთ ახლავე გაიაროთ რეგისტრაცია Unicode-ის მეათე საერთაშორისო
კონფერენციაზე დასასწრებად, რომელიც გაიმართება 10-12 მარტს,
ქ. მაინცში, გერმანიაში. კონფერენცია შეჰკრებს ერთად მსოფლიოს
ექსპერტებს ისეთ დარგებში როგორიცაა ინტერნეტი და Unicode-ი,
ინტერნაციონალიზაცია და ლოკალიზაცია, Unicode-ის გამოყენება
ოპერაციულ სისტემებსა, და გამოყენებით პროგრამებში, შრიფტებში,
ტექსტების დამუშავებასა და მრავალენოვან კომპიუტერულ სისტემებში.
Russian:
From a Unicode conference invitation:
Зарегистрируйтесь сейчас на Десятую Международную Конференцию по
Unicode, которая состоится 10-12 марта 1997 года в Майнце в Германии.
Конференция соберет широкий круг экспертов по вопросам глобального
Интернета и Unicode, локализации и интернационализации, воплощению и
применению Unicode в различных операционных системах и программных
приложениях, шрифтах, верстке и многоязычных компьютерных системах.
Thai (UCS Level 2):
Excerpt from a poetry on The Romance of The Three Kingdoms (a Chinese
classic 'San Gua'):
[----------------------------|------------------------]
๏ แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช พระปกเกศกองบู๊กู้ขึ้นใหม่
สิบสองกษัตริย์ก่อนหน้าแลถัดไป สององค์ไซร้โง่เขลาเบาปัญญา
ทรงนับถือขันทีเป็นที่พึ่ง บ้านเมืองจึงวิปริตเป็นนักหนา
โฮจิ๋นเรียกทัพทั่วหัวเมืองมา หมายจะฆ่ามดชั่วตัวสำคัญ
เหมือนขับไสไล่เสือจากเคหา รับหมาป่าเข้ามาเลยอาสัญ
ฝ่ายอ้องอุ้นยุแยกให้แตกกัน ใช้สาวนั้นเป็นชนวนชื่นชวนใจ
พลันลิฉุยกุยกีกลับก่อเหตุ ช่างอาเพศจริงหนาฟ้าร้องไห้
```
--------------------------------
### Run httpbin Locally with Docker
Source: https://github.com/postmanlabs/httpbin/blob/master/README.md
This snippet provides commands to pull the httpbin Docker image and run it locally, making the service accessible on port 80. It's useful for local development and testing without relying on the public httpbin.org instance.
```sh
docker pull kennethreitz/httpbin
docker run -p 80:80 kennethreitz/httpbin
```
--------------------------------
### httpbin API Endpoints Reference
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/httpbin.1.html
Comprehensive list of available httpbin API endpoints for testing HTTP requests and responses, including various data manipulation, authentication, redirection, and content generation functionalities.
```APIDOC
/now.httpbin.org: The current time, in a variety of formats.
/: This page.
/ip: Returns Origin IP.
/uuid: Returns UUID4.
/user-agent: Returns user-agent.
/headers: Returns header dict.
/get: Returns GET data.
/post: Returns POST data.
/patch: Returns PATCH data.
/put: Returns PUT data.
/delete: Returns DELETE data.
/anything: Returns request data, including method used.
/anything/:anything: Returns request data, including the URL.
/base64/:value: Decodes base64url-encoded string.
/encoding/utf8: Returns page containing UTF-8 data.
/gzip: Returns gzip-encoded data.
/deflate: Returns deflate-encoded data.
/brotli: Returns brotli-encoded data.
/status/:code: Returns given HTTP Status code.
/response-headers?key=val: Returns given response headers.
/redirect/:n: 302 Redirects n times.
/redirect-to?url=foo: 302 Redirects to the foo URL.
/redirect-to?url=foo&status_code=307: 307 Redirects to the foo URL.
/relative-redirect/:n: 302 Relative redirects n times.
/absolute-redirect/:n: 302 Absolute redirects n times.
/cookies: Returns cookie data.
/cookies/set?name=value: Sets one or more simple cookies.
/cookies/delete?name: Deletes one or more simple cookies.
/basic-auth/:user/:passwd: Challenges HTTPBasic Auth.
/hidden-basic-auth/:user/:passwd: 404'd BasicAuth.
/digest-auth/:qop/:user/:passwd/:algorithm: Challenges HTTP Digest Auth.
/digest-auth/:qop/:user/:passwd: Challenges HTTP Digest Auth.
/stream/:n: Streams min(n, 100) lines.
/delay/:n: Delays responding for min(n, 10) seconds.
/drip?numbytes=n&duration=s&delay=s&code=code: Drips data over a duration after an optional initial delay, then (optionally) returns with the given status code.
/range/1024?duration=s&chunk_size=code: Streams n bytes, and allows specifying a Range header to select a subset of the data. Accepts a chunk_size and request duration parameter.
/html: Renders an HTML Page.
/robots.txt: Returns some robots.txt rules.
/deny: Denied by robots.txt file.
/cache: Returns 200 unless an If-Modified-Since or If-None-Match header is provided, when it returns a 304.
/etag/:etag: Assumes the resource has the given etag and responds to If-None-Match header with a 200 or 304 and If-Match with a 200 or 412 as appropriate.
/cache/:n: Sets a Cache-Control header for n seconds.
/bytes/:n: Generates n random bytes of binary data, accepts optional seed integer parameter.
```
--------------------------------
### httpbin Core API Endpoints Reference
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/httpbin.1.html
A comprehensive list of core httpbin API endpoints, detailing their functionality, parameters, and expected responses. These endpoints are designed for testing various HTTP scenarios, including streaming, image retrieval, form submissions, and XML responses.
```APIDOC
Endpoints:
/stream-bytes/:n:
Description: Streams n random bytes of binary data in chunked encoding.
Parameters:
n (integer): The number of bytes to stream.
seed (integer, optional): An optional seed for random data generation.
chunk_size (integer, optional): An optional size for each data chunk.
/links/:n:
Description: Returns a page containing n HTML links.
Parameters:
n (integer): The number of HTML links to generate.
/image:
Description: Returns an image based on the client's Accept header.
/image/png:
Description: Returns a PNG image.
/image/jpeg:
Description: Returns a JPEG image.
/image/webp:
Description: Returns a WEBP image.
/image/svg:
Description: Returns an SVG image.
/forms/post:
Description: Returns an HTML form that submits data to the /post endpoint.
/xml:
Description: Returns a sample XML document.
```
--------------------------------
### Integrate Gauges Analytics Tracking Script
Source: https://github.com/postmanlabs/httpbin/blob/master/httpbin/templates/trackingscripts.html
This JavaScript snippet initializes the Gauges tracking object and dynamically inserts the Gauges tracking script into the HTML document. It sets the site ID and tracking path, ensuring that page views and other interactions are sent to the specified Gauges analytics account.
```JavaScript
var _gauges = _gauges || []; (function() { var t = document.createElement('script'); t.type = 'text/javascript'; t.async = true; t.id = 'gauges-tracker'; t.setAttribute('data-site-id', '58cb2e71c88d9043ac01d000'); t.setAttribute('data-track-path', 'https://track.gaug.es/track.gif'); t.src = 'https://d36ee2fcip1434.cloudfront.net/track.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(t, s); })();
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.