' declare some help variables we will need
Dim response As BANanoFetchResponse
Dim error As BANanoObject
Dim data As BANanoJSONParser
' list (GET is default, and we do not need extra options so we pass Null for the options)
Dim fetch1 As BANanoFetch
fetch1.Initialize("https://jsonplaceholder.typicode.com/posts", Null)
fetch1.Then(response)
' we got a response, but as the Json() method returns a Promise, we will need to process it in the next 'then' so we return it to this Fetch
fetch1.Return(response.Json)
fetch1.Then(data)
' the Json promise is resolved, lets log it...
Log(data)
fetch1.End ' always end a fetch with this!
' insert with a POST
Dim fetch2Options As BANanoFetchOptions
fetch2Options.Initialize
fetch2Options.Method = "POST"
fetch2Options.Body = BANano.ToJson(CreateMap("title": "foo", "body": "bar", "userId": 1))
fetch2Options.Headers = CreateMap("Content-type": "application/json; charset=UTF-8")
Dim fetch2 As BANanoFetch
fetch2.Initialize("https://jsonplaceholder.typicode.com/posts", fetch2Options)
fetch2.Then(response)
fetch2.Return(response.Json)
fetch2.Then(data)
Log(data)
fetch2.End
' update with a PATCH
Dim fetch3Options As BANanoFetchOptions
fetch3Options.Initialize
fetch3Options.Method = "PATCH"
fetch3Options.Body = BANano.ToJson(CreateMap("title": "foo changed"))
fetch3Options.Headers = CreateMap("Content-type": "application/json; charset=UTF-8")
Dim fetch3 As BANanoFetch
fetch3.Initialize("https://jsonplaceholder.typicode.com/posts/1", fetch3Options)
fetch3.Then(response)
fetch3.Return(response.Json)
fetch3.Then(data)
Log(data)
fetch3.End
' delete with a DELETE
Dim fetch4Options As BANanoFetchOptions
fetch4Options.Initialize
fetch4Options.Method = "DELETE"
Dim fetch4 As BANanoFetch
fetch4.Initialize("https://jsonplaceholder.typicode.com/posts/1", fetch4Options)
fetch4.End