Introduction to HTTP Requests AND Responses

Overview of Section - HTTP Requests and Responses

  • Headers
  • Responses
    • Status Codes - e.g. 200, 404, 500
  • This is the foundation for most web, HTTP, REST testing and automating.

HTTP GET Request sent from cURL


curl ^
-H "accept: application/xml" ^

Sends a GET Request:

User-Agent: curl/7.39.0
Connection: Keep-Alive
accept: application/xml
  • GET requests retrieve information from the Web Application
  • important stuff:
    • Verb (GET),
    • Http version (1.1),
    • User-Agent,
    • Accept,
    • Host,
    • endpoint

HTTP Response to GET /heartbeat request

HTTP/1.1 204 OK
Date: Thu, 17 Aug 2017 10:34:32 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Server: Jetty(9.4.4.v20170414)
  • cURL response was same but content-type was application/xml
  • important stuff: Status Code (204 OK), Http version (1.1), Date, Content-Type

Raw HTTP Requests and Responses

  • we need to be able to read them
  • we will rarely have to create them by hand
  • lookup headers you don't know
  • some fields are for the server some are for the application some are documentation

Basic HTTP Verbs

  • GET - retrieve data
  • POST amend/create from partial information
  • PUT - create or replace from full information
  • DELETE - delete items
  • OPTIONS - verbs available on this url


HTTP Status Codes

  • 1xx Informational
    • 100 Continue
  • 2xx Success
    • e.g. 200 OK
  • 3xx Redirection
    • e.g. 301 Moved Permanently
  • 4xx Client Error
    • e.g. 404 Not Found
  • 5xx Server Error
    • e.g. 500 Internal Server Error

Common HTTP Status Codes

Status Code Status Code
200 OK 405 Method Not Allowed
201 Created 409 Conflict
301 Moved Permanently 500 Internal Server Error
307 Temporary Redirect 501 Not Implemented
400 Bad Request 502 Bad Gateway
401 Unauthorized 503 Service Unavailable
403 Forbidden 504 Gateway Timeout
404 Not Found

HTTP Status code references


HTTP Message Body Format - JSON

  • JSON - JavaScript Object Notation
  • an actual Object in JavaScript
  • common data transfer and marshalling format for other languages
  • schema exists for JSON

JSON Example Explained

    "title":"a list title",
  • An object, which has an array called "lists".
  • the lists array contains an object with fields: guid, title, description, createdDate, amendedDate - all String fields.

HTTP Message Body Format - XML

  • XML - eXtended Markup Language
  • HTML is often XML
  • another common marshalling format
  • can be validated against XML schema

XML Example Explained

<?xml version="1.0" encoding="UTF-8" ?>
    <title>a list title</title>
  • elements, nested elements
  • tags, values

URI - Universal Resource Identifier


    • scheme = http
    • host =
    • path = apps/api/mock/reflect

A URL is a URI


  • URI - Universal Resource Identifier
    • 'generic' representation - might not include the 'scheme'
    • /apps/api/mock/reflect
  • URL - Universal Resource Locator
    • defines how to locate the identified resource
  • URN - Universal Resource Name
    • not often used - uses scheme urn


  • http
  • https
  • ftp
  • mailto
  • file

Query Strings

GET /lists/{guid}?without=title,description

Query String:

  • starts with ?
  • params separated with &

More About Query Strings

GET /lists/{guid}?without=title,description
  • usually name=value pairs separate by '&'
    • convention since anything after the ? is the Query string
    • app then parses as required
  • can be used with any verb
  • GET request - all params are send as query strings

HTTP Standards?

How to test with this information

  • Read the standards for the verbs and the status codes.
  • Projects often argue about interpretations.
  • Some of the standards are exact enough that it is possible to say "I observed X" it does not match the standard - include links and quotes to the standards.

HTTP Headers

  • Headers are Key: value pair attributes in the request
  • Headers are not counted as the payload
  • Headers help configure the response from the server and tell the server how to process this request
  • e.g. a GET request with an accept: application/xml header is asking the server to respond with the information in XML format

User-Agent Header

  • Often not sent when accessing an API
  • Marks request as coming from a browser
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/60.0.3112.90 Safari/537.36

Accept Header

  • Defines the payload types that the receiver will accept
  • If this was an API call it would likely return XML
Accept: text/html,application/xhtml+xml,application/xml;

Common values:

  • text/html
  • application/json
  • application/xml

Basic Auth Header

  • An application might use Basic Auth Authentication to control access to the API
  • Authorization Header

e.g. Authorization: Basic dXNlcjpwYXNzd29yZA==

dXNlcjpwYXNzd29yZA== is base64 encoded "user:password"


  • cURL you need to add the header
  • Postman & Insomnia use the Authorization and Auth tabs