NotesHttpRequest LotusScript example

NotesHttpRequest is a new LotusScript class in Notes V10.0.1 used to make HTTP requests to web servers.

The example wraps the get(), post(), put() and deleteResource() methods in a LotusScript class.

I have also put together a small Node.js / Express.js project that can be used as test server for the NotesHttpRequest example.

Class HttpRequestWrapper

%REM
	Library 10010.http
	Created Jan 8, 2019 by Ulrich Krause/singultus
%END REM
Option Public
Option Declare

Const BASE_URL_PORT = "http://192.168.178.35:3001/api/"
Const CLASS_CUSTOMER ="customers"

Const CUSTOMER_5 = |{
					"firstname" : "Ulrich",
					"lastname" : "Krause",
					"age" : 59,
					"id" : 5
				}|

Const CUSTOMER_5_UPDATE = |{
					"firstname" : "Heinz Ulrich",
					"lastname" : "Krause",
					"age" : 59,
					"id" : 5
				}|
				
%REM
	Class HttpRequestWrapper
%END REM
Public Class HttpRequestWrapper
	
	Private m_session As NotesSession
	Private m_url As String
	Private m_class As String
	Private m_json As String
	Private m_httpRequest As NOTESHTTPREQUEST
	
	%REM
		Sub New
	%END REM
	Public Sub New()
		Set m_session = New NotesSession
		Set m_httpRequest = me.m_session.CreateHttpRequest()
		
		m_httpRequest.Preferstrings = True
		
		m_url = BASE_URL_PORT
		m_class = CLASS_CUSTOMER
	End Sub
	
	%REM
		Function getApiVersion
	%END REM
	Public sub getApiVersion()
		m_json = m_httpRequest.Get(BASE_URL_PORT)
		MsgBox m_json
	End Sub
	
	%REM
		Sub getAllObj
	%END REM
	Public Sub getAllObj()
		m_json = m_httpRequest.Get(_
		BASE_URL_PORT + CLASS_CUSTOMER)
		
		MsgBox m_json
	End Sub
	
	%REM
		Sub getObjById
	%END REM
	Public Sub getObjById(id As String)
		m_json = m_httpRequest.Get(_
		BASE_URL_PORT + CLASS_CUSTOMER + "/" + id)
		
		MsgBox m_json	
	End Sub
	
	%REM
		Sub createObj
	%END REM
	Public Sub createObj()
		m_json = m_httpRequest.Post(_
		BASE_URL_PORT + CLASS_CUSTOMER,_
		removeCRLF(CUSTOMER_5))
		
		MsgBox m_json	
	End Sub
	
	%REM
		Sub updateObj
	%END REM
	Public Sub updateObj(id As String)
		m_json = m_httpRequest.Put(_
		BASE_URL_PORT + CLASS_CUSTOMER + "/" + id,_
		removeCRLF(CUSTOMER_5_UPDATE))
		
		MsgBox m_json
	End Sub
	
	%REM
		Sub deleteObj
	%END REM
	Public Sub deleteObj(id As String)
		m_json = m_httpRequest.DeleteResource(_
		BASE_URL_PORT + CLASS_CUSTOMER + "/" + id)
		
		MsgBox m_json
	End Sub
End Class

Public Function removeCRLF(json As String) As String
	removeCRLF = Replace(Replace(json, Chr(13), ""),Chr(10),"")
End Function

Sample usage:

Use "10010.http"

Sub Click(Source As Button)
	Dim httpRequestWrapper As New HttpRequestWrapper()

	Call httpRequestWrapper.getApiVersion()
	Call httpRequestWrapper.createObj()
	Call httpRequestWrapper.deleteObj("3")
	Call httpRequestWrapper.getAllObj()
	Call httpRequestWrapper.updateObj("5")
	Call httpRequestWrapper.getObjById("5")
End Sub


One thought on “NotesHttpRequest LotusScript example

  1. Hi Ulrich – Looks like the Post(URL, ValueV) method of NotesHTTPRequest has a 64k limit too, just like NotesJSONNavigator.

    If I pass a ValueV larger than 64k, it gets truncated to 65535 bytes upon post. Tried lots of workarounds including passing a Variant List instead of a string, NotesStreams and so on, sadly nothing gets around the limit.

    So although these new classes are OK for simple REST APIs, once you start passing around Base64 encoded JPEGs, both new sets of classes fall over.

Comments are closed.