Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A request is an action we send to interact with a web service, whether you are authenticating or interacting with the resource server. Working with requests is required if Iguana is acting as either the:

  • Client - building requests to be sent to the Server.

  • Server - listening for incoming requests and parsing them for processing.

HTTP requests are made up of four parts. Take this example client request to a FHIR API request: screenshot

...

Expand
title1) Method - the action to be performed on a resource

The method indicates the action to be performed on a resource within the API. 

With Iguana’s net.http.* library, you can invoke different HTTP methods:  

  • net.http.get{} - query or retrieve resources.

  • net.http.post{} - to add or create a resource.

  • net.http.put{} - update an existing resource.

  • net.http.delete{} - remove a resource.

Expand
title2) Endpoint - the URL where the resource is found

The URL defines where the client can access the desired resources - for example the Patient resource.  

Code Block
url='http://hapi.fhir.org/baseR4/Patient'

Query String:

For GET requests, the URL may also contain any necessary query parameters like the id of the patient you are searching for.  .  The ? indicates the end of the url and beginning of the parameters. Key-value pairs are separated by &.

Code Block
http://hapi.fhir.org/baseR4/Patient?id=12324&name=Bruce

These URLs can be hardcoded if necessary, or built using various URL Encoding strategies.

Expand
title3) Header - the metadata providing information about the request

The header includes metadata requirements defined by the API to provide information about the request.

Code Block
headers= {
  ['Content-Type'] = 'application/fhir+json',
  ['Authorization'] = 'Bearer '..token
}

This can contain information such as: 

  • Connection and content types 

  • Authentication information like credentials, cookies, or an access token

  • MIME types

  • Entity tags (ETAGS)

Expand
title4) Body - the payload of the request, containing the content to be sent

Some requests (PUT and POST) require a body where we add the resource content or additional information to be sent to the server. This can be in a few potential formatsThe HTTP formats will typically be specified by the API you’re working with and often requires the appropriate Content-Type header. Common formats include:

JSON

Code Block
languagejson
[{
    "patientid": "33751",
    "status": "active",
    "firstname": ”Bruce",
    "lastname": ”Wayne",
	...
}]

XML

Code Block
languagexml
<patient>
  <patientid>33751</patientid>
   <status>active</status>
   <firstname>Bruce</firstname>
   <lastname>Wayne</lastname>
</patient>

Query String format

Code Block
patientid=33751&status=active&firstname=Bruce&lastname=Wayne

Form Data

Code Block
languagelua
local formData = {
      ["file"] = "@/path/to/file.txt",
      ["name"] = "Bruce Wayne",
      ["email"] = "bruce.wayne@example.com"
   }

Form data for data sent from a web form. Typically handled in Lua using string or table functions, storing data as name-value pairs.