### Example HTTPSpec GET Request with Assertions Source: https://github.com/bradcypert/httpspec/blob/main/HTTPSpec.md Illustrates a basic GET request to retrieve a user by ID, including an Authorization header with a placeholder token, and assertions for the expected HTTP status code and content length of the response. ```HTTPSpec ### Get user by ID GET https://api.example.com/users/123 Authorization: Bearer {{token}} Accept: application/json //# status == 200 //# header["content-length"] = 2345 ``` -------------------------------- ### Complete HTTPSpec File Example with Multiple Requests Source: https://github.com/bradcypert/httpspec/blob/main/HTTPSpec.md A comprehensive example demonstrating a full HTTPSpec file, including variable definition, a GET request to fetch user data, and a POST request to create a new user, each with their respective assertions, showcasing the ability to define multiple test scenarios within a single file. ```HTTPSpec @token = abc123 ### Get user by ID GET https://api.example.com/users/123 Authorization: Bearer {{token}} Accept: application/json //# status == 200 //# header["Content-Type"] == "application/json" //# body.id == 123 //# body.email contains "@example.com" ### Create new user POST https://api.example.com/users Content-Type: application/json { "name": "Alice" } //# status == 201 //# body.name == "Alice" ``` -------------------------------- ### Define Sequential HTTP Requests with Assertions Source: https://github.com/bradcypert/httpspec/blob/main/README.md Illustrates the structure of an .http or .httpspec file, defining multiple HTTP GET requests. It demonstrates how requests are executed in sequence and how an assertion failure (e.g., //# status == 403 for a 404 response) can halt further execution of the test file. ```HTTP File ### Make a simple 200 request to HTTP Bin GET http://httpbin.org/status/200 Content-Type: application/json ### Make a simple 404 request to HTTP Bin GET http://httpbin.org/status/404 Content-Type: application/json //# status == 403 ### Make a simple 201 request to HTTP Bin GET http://httpbin.org/status/201 Content-Type: application/json ``` -------------------------------- ### HTTPSpec Assertion Syntax Examples Source: https://github.com/bradcypert/httpspec/blob/main/HTTPSpec.md Shows various assertion types available in HTTPSpec, including checking HTTP status codes, specific header values, JSON body content using dot notation, and substring presence within the response body. ```HTTPSpec GET https://api.example.com/users/123 //# status == 200 //# header["Content-Type"] == "application/json" //# body.id == 123 //# body.name == "John Doe" //# body.email contains "@example.com" ``` -------------------------------- ### HTTPSpec JSON Path Assertion Example Source: https://github.com/bradcypert/httpspec/blob/main/HTTPSpec.md Illustrates how to access nested elements within a JSON array in the response body using dot notation combined with bracketed indices for precise assertions. ```HTTPSpec body.data[0].id == 1 ``` -------------------------------- ### Execute Httpspec Tests from Command Line Source: https://github.com/bradcypert/httpspec/blob/main/README.md Provides the basic command-line syntax for running Httpspec tests. It shows how to specify the path to an .http or .httpspec file and includes a sample output demonstrating a test failure and the overall test summary. ```bash httpspec ./test_files/httpbin_test.http # or whatever your filepath is to your .http or .httpspec file # Sample output Running test 1: ./test_files/httpbin_test.http [Fail] Expected status code 403, got 404 All 1 tests ran successfully! Pass: 0 Fail: 1 ``` -------------------------------- ### HTTPSpec Variable Definition and Substitution Source: https://github.com/bradcypert/httpspec/blob/main/HTTPSpec.md Demonstrates how to define a variable using the '@' prefix and then reference it within a request's headers or URL using the '{{variable}}' syntax for dynamic values. ```HTTPSpec @token = abc123 GET https://api.example.com/users/123 Authorization: Bearer {{token}} ``` -------------------------------- ### Configure Httpspec Thread Pool for Concurrency Source: https://github.com/bradcypert/httpspec/blob/main/README.md Explains how to adjust the concurrency level of Httpspec's test runner. By setting the HTTP_THREAD_COUNT environment variable, users can specify the number of jobs in the thread pool, which is useful for optimizing test execution speed. ```bash HTTP_THREAD_COUNT=4 httpspec ./my_project/httptests/ ``` -------------------------------- ### HTTPSpec Request Block Structure Source: https://github.com/bradcypert/httpspec/blob/main/HTTPSpec.md Defines the general structure of an HTTPSpec request block, including HTTP method, URL, headers, optional request body, and a dedicated section for assertions. ```HTTPSpec ### Optional comment or test name [HTTP_VERSION] : ... //# ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.