Skip to content
Easit AB edited this page Apr 24, 2021 · 4 revisions

Table of Contents

  1. Parameters when running script
  2. Routing
  3. Identifier lookup
  4. Logging
  5. EventHandlerExample

Parameters when running script

  • BindingUrl = 'http://localhost'
  • Port = '9080'
  • Basedir = 'resources'
  • ErrorHandling = 'SilentlyContinue'
  • RequestOutput = 'false'
  • ResponseOutput = 'false'

More info and details

Routing

/testfromeasit

Method: POST

Response

  • Status code: 200
  • HTML-body: Success!

/fromeasit

Method: POST

Response

  • Status code: 200
  • HTML-body: Success!

Action taken

  1. Checks if content type is 'text/xml; charset=UTF-8', if not the server will log 'Invalid content type'.
  2. Identifier lookup (More details below). If no match is found the server will log 'No identifier found...'.
  3. Convert content of http request from XML to PSObject. Each item will result in a PSObject and each item property will be added to each PSObject as a Property. Each object is added to an array namned 'easitObjects'.
  4. Setting "execDir". execDir = "PathToStart-start-httpserver.ps1\ValueFromParameterNamedBasedir"
  5. Setting "executable". executable = "$execDir$identifier.ps1"
  6. Executing executable with cmdlet Start-Job and passing in the array 'easitObjects' and variable 'execDir'.

/toeasit

Method: POST

  • Status code: 200
  • HTML-body: Success!

Action taken

  1. Checks if content type contains 'application/json', if not the server will log 'Invalid content type'.
  2. Converts content of http request from json to PSObject with cmdlet ConvertFrom-Json, result is stored in array 'requestObjects'.
  3. Identifier lookup (More details below). If no match is found the server will log 'No identifier found...'.
  4. Setting "execDir". execDir = "PathToStart-start-httpserver.ps1\ValueFromParameterNamedBasedir"
  5. Setting "executable". executable = "$execDir$identifierJSON.ps1"
  6. Executing executable with cmdlet Start-Job and passing in the array 'requestObjects' and variable 'execDir'.

/status

Method: GET

Response

  • Status code: 200
  • HTML-body: Staus: OK!

/quit

Method: GET

Response

  • Status code: 200
  • HTML-body: Stopping powershell http server... Goodbye!

/exit

Method: GET

Response

  • Status code: 200
  • HTML-body: Stopping powershell http server... Goodbye!

Default (if none the above endpoints have been specified)

Response

  • Status code: 204
  • HTML-body: Unknown endpoint or action!

Identifier lookup

Depending on what content type is used lookup for identifier is approach diffently.

Content type

text/xml; charset=UTF-8

In the case of content type xml the following regex 'itemIdentifier">(.)</' is used for lookup. itemIdentifier is an property that you can specify in the export configuration in Easit GO. If itemIdentifier is not found the following regex is used 'identifier">(.)</'. identifier is an property specified in the item event rule in Easit GO. All lookups is done against the http request body.

application/json

In the case of content type json the following regex '(?|&)identifier=(.*)(&)?' is used against the request URL for lookup. If identifier is not found in the request URL the same method for lookup as for content type xml is used.

Logging

Logging is handled by inline function name 'Write-CustomLog'. Behaviour for this function can be changed by changing values in loggerSettings.xml Default logging is done at INFO-level to PShttpServer.log in the same folder as start-httpserver.ps1 is in.

Params that can be changed in loggerSettings.xml

  • LogName = 'PShttpServer' (Name of logfile for PSHttpServer)
  • LogDirectory = 'logs' (Subfolder, relative to start-httpserver.ps1, where logs are written to)
  • LogLevelSwitch = 'INFO' (Level of logging output)
  • writeToHost = 'false' (If script is running in console and output should be written to host, change to true)
  • ErrorHandling = 'SilentlyContinue' (How should server handle errors, if this is set to Stop script will stop upon an error)
  • RotationInterval = '30' (For how many days should logs be saved)

More info and details

EventHandlerExample

Information and details