https://github.com/dwolfhub/corona_httprequest
send http requests and provide callbacks for success and failure of request
https://github.com/dwolfhub/corona_httprequest
Last synced: 16 days ago
JSON representation
send http requests and provide callbacks for success and failure of request
- Host: GitHub
- URL: https://github.com/dwolfhub/corona_httprequest
- Owner: dwolfhub
- License: mit
- Created: 2013-07-16T19:59:33.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-07-16T20:21:09.000Z (over 12 years ago)
- Last Synced: 2025-01-19T06:44:08.172Z (12 months ago)
- Language: Lua
- Size: 121 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP Request Library
#### File Name
requesthttp.lua
#### Note
The HTTP request is asynchronous and therefore callback functions must be entered in order to process the data when it comes back.
The onError callback is run when the flag isError that comes back with the request is marked true. Status codes are ignored. If you need to consider a 404 status code an error for example, place that logic in your onSuccess callback function.
## RequestHttp:send(endPoint, method, queryString, onSuccess, onError)
#### Parameters
> - endPoint (string) the URL that the request should go to
> - method (string) the method of the request
> - header (table)
> - queryString (string) the query string of data to send with the request
> - onSuccess (func) function to run when the request is successful
> - onError (func) function to run when the request is successful
#### Return
> void
### Example
```lua
local endPoint = 'https://www.API.com'
local method = "POST"
local header = {
["X-API-KEY"] = "AAAAAAAAAAAAAAAAAAA"
}
local queryString = "field1=foo&field2=bar"
local onSuccess = function (returnData)
print('onSuccess Processed')
end
local onError = function (returnData)
print('onError processed')
end
local requestHttp = require "library.core.http.requesthttp"
requestHttp.send(endPoint, method, header, queryString, onSuccess, onError)
```