Skip to content

mesopelagique/HTTPRequestBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

HTTPClassBuilder

Why using builder pattern

Builder pattern allow

  • to do one line of code to configure the request
  • to have code completion for request configuration features (instead of knowning by heart the property names of 4D.HTTPRequest)

Usage

var $client : cs.HTTPClient
$client:=cs.HTTPClient.new()

Simple get request

$client.get("https://httpbin.org/")\
  .onTerminate(Formula(ALERT(JSON Stringify($1.response))))\
  .build()\
  .wait()

or just getting request without waiting synchronously

var $request: 4D.HTTPREquest
$request:=$client.get("https://httpbin.org/")\
  .onTerminate(Formula(ALERT(JSON Stringify($1.response))))\
  .build()

Simple get request in my class with function receiveHttpBinData as callback

Class constructor
  This.client:=cs.HTTPClient.new()
Function receiveHttpBinData($response : Object; $event : Object)
  // ...
Function run()
  $client.get("https://httpbin.org/")\
    .onTerminate(This.receiveHttpBinData)\
    .build()\
    .wait()

More "complex" request

$client.request()\
	.GET()\
	.url("https://httpbin.org/")\
	.appendHeader("Toto"; "Totovalue")\
	.version(1)\
	.onTerminate(Formula(ALERT(JSON Stringify($1.response))))\
	.build()\
	.wait()

About

Create HTTP request using builder pattern

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages