Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-dill committed May 18, 2020
2 parents 08c81eb + 66fba09 commit 28603a4
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 97 deletions.
53 changes: 25 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@

# Roblox Requests 0.2.0
# Roblox Requests

**Roblox Requests** brings user-friendly HTTP to Roblox with no need for the manual labor of HttpService.

With Requests you can send robust, human-readable HTTP requests without ever having to deal with the underlying HttpService.
No more manual query strings or encoding POST data.

## Roblox Requests Features

- Sessions with cookie persistence, base URLs/headers
- Automatic query string building
- Automatic JSON body encoding
- Builtin Response object and JSON decoding
- Domain based Key/Value cookies
- Multipart form building including file encoding and upload
- Global ratelimiting with per-session config options

---

An example of what you can do with Requests:
#### The Power of Roblox Requests:

```lua
local http = require(game.ReplicatedStorage.http)
local r = http.get("https://api.github.com/orgs/Roblox/repos")

local r = http.post("https://httpbin.org/post", {
query = {arg="value"},
data = {this="json"}
})
print(r.status_code, r.message)
-- 200 OK

print(r.content_type,
r:json().url)
repos = r:json()
print(#repos)
-- 30

-- output:
print(r.content_type)
-- application/json
-- https://httpbin.org/post?arg=value
print(r.encoding)
-- utf-8
print(r.headers["x-ratelimit-remaining"])
-- 59
```

See [similar code with HttpService.](https://gist.github.com/jpatrickdill/8fe2a82c47c1bdf679eb1a1c5f07d7a0)
Roblox Requests will bring simple support for all internet resources to your game.

## Features

Requests' powerful API allows you to send HTTP/1.1 requests without the need of manual labor. You'll never
have to add query strings to URLs or encode your POST data again.
- Sessions with Cookie Persistence
- Default Headers, URL prefixes
- Automatic Query Strings
- JSON Body Encoding, JSON Response Decoding
- Elegant Key/Value Cookies
- Domain/Path filters
- Multipart File Encoding and Upload
- Global/Per-Session Ratelimiting


## [Documentation](https://jpatrickdill.github.io/roblox-requests/guide/installation/)
Roblox Requests was inspired by the well known [Python Requests](https://2.python-requests.org/en/master/) library.

[In this documentation](https://jpatrickdill.github.io/roblox-requests/guide/installation/) you'll find step-by-step instructions to get the most out of Roblox Requests.
14 changes: 14 additions & 0 deletions default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "roblox-requests",
"tree": {
"$className": "DataModel",

"ReplicatedStorage": {
"$className": "ReplicatedStorage",

"http": {
"$path": "http"
}
}
}
}
6 changes: 3 additions & 3 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ will not block the current thread.
- **request** (Request) - Request that generated this response
- **url** (string) - Requests' URL
- **method** (string) - Request's HTTP method
- **success** (bool) - `true` if response was successful
- **code** (number) - Status code of reponse
- **ok** (bool) - `true` if response has OK status code (200 \<= code \< 300)
- **status_code** (number) - Status code of reponse
- **message** (string) - Status message of response
- **headers** (dictionary) - Headers sent in response
- **content** (string) - Response body
- **text** (string) - Response body
- **cookies** (CookieJar) - New cookies sent in this response

### Response:json
Expand Down
26 changes: 0 additions & 26 deletions docs/changes.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ print(r.headers["Last-Modified"])
-- Wed, 08 Oct 2014 23:28:44 GMT
```

This dictionary, however, is special. HTTP headers are case-insensitive, so you can access them however you like:
HTTP headers are case-insensitive, so you can access them however you like:

```lua
print(r.headers["Last-Modified"])
Expand Down
Binary file added docs/img/with.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/without.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 25 additions & 21 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
# Roblox Requests {{ version }}
# Roblox Requests

**Roblox Requests** brings user-friendly HTTP to Roblox with no need for the manual labor of HttpService.

---
With Requests you can send robust, human-readable HTTP requests without ever having to deal with the underlying HttpService.
No more manual query strings or encoding POST data.

An example of what you can do with Requests:
#### The Power of Roblox Requests:

```lua
local http = require(game.ReplicatedStorage.http)
local r = http.get("https://api.github.com/orgs/Roblox/repos")

local r = http.post("https://httpbin.org/post", { query = {arg="value"},
data = {key="value"} })
print(r.status_code, r.message)
-- 200 OK

print(r.content_type,
r:json().url)
repos = r:json()
print(#repos)
-- 30

-- output:
print(r.content_type)
-- application/json
-- https://httpbin.org/post?arg=value
print(r.encoding)
-- utf-8
print(r.headers["x-ratelimit-remaining"])
-- 59
```

See [similar code with HttpService.](https://gist.github.com/jpatrickdill/8fe2a82c47c1bdf679eb1a1c5f07d7a0)
Roblox Requests will bring simple support for all internet resources to your game.

Requests' powerful API allows you to send HTTP/1.1 requests without the need of manual labor. You'll never
have to add query strings to URLs or encode your POST data again.
## Features

### Roblox Requests Features
- Sessions with Cookie Persistence
- Default Headers, URL prefixes
- Automatic Query Strings
- JSON Body Encoding, JSON Response Decoding
- Elegant Key/Value Cookies
- Domain/Path filters
- Multipart File Encoding and Upload
- Global/Per-Session Ratelimiting

- Sessions with cookie persistence, base URLs/headers
- Automatic query string building
- Automatic JSON body encoding
- Builtin Response object and JSON decoding
- Domain based Key/Value cookies
- Multipart form building including file encoding and upload
- Global ratelimiting with per-session config options

Roblox Requests was inspired by the well known [Python Requests](https://2.python-requests.org/en/master/) library.

Expand Down
8 changes: 8 additions & 0 deletions example.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local HttpService = game:GetService("HttpService")

local body = HttpService:JSONEncode({cookies = "milk"})
local r = HttpService:RequestAsync({Url = "https://httpbin.org/put", Method="PUT", Body=body})

if r.Success then
data = HttpService:JSONDecode(r.Body)
end
2 changes: 1 addition & 1 deletion http/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local RateLimiter = require(Src.ratelimit)

local http = {}

http.VERSION = "0.2.0"
http.VERSION = "0.2.1"

http.Request = Request.new
http.Session = Session.new
Expand Down
21 changes: 16 additions & 5 deletions http/src/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,25 @@ function Response.new(req, resp, rt)
self.method = req.method

-- response data
self.success = resp.Success
self.code = resp.StatusCode
self.code = resp.StatusCode -- deprecated
self.status_code = resp.StatusCode

self.success = resp.Success -- deprecated
self.ok = self.status_code >= 200 and self.status_code < 300

self.message = resp.StatusMessage
self.headers = CaseInsensitive(resp.Headers)
self.content = resp.Body

self.content = resp.Body -- deprecated
self.text = resp.Body


-- additional metadata for quick access
self.content_type = self.headers["content-type"]
local type_encoding = self.headers["content-type"]:split(";")
self.content_type = type_encoding[1]
self.encoding = (type_encoding[2] and type_encoding[2]:split("=")[2]) or "" -- or "utf-8"


self.content_length = self.headers["content-length"] or #self.content

-- cookies
Expand All @@ -47,7 +58,7 @@ function Response.new(req, resp, rt)
end

function Response:__tostring()
return self.content
return self.text
end

function Response:json()
Expand Down
3 changes: 1 addition & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ plugins:

nav:
- Home: index.md
- Release Notes: changes.md
- Guide:
- Installation: guide/installation.md
- Quickstart: guide/quickstart.md
Expand All @@ -27,4 +26,4 @@ nav:


extra:
version: 0.2.0
version: 0.2.1
10 changes: 0 additions & 10 deletions rojo.json

This file was deleted.

0 comments on commit 28603a4

Please sign in to comment.