Skip to content

Commit

Permalink
attribute names
Browse files Browse the repository at this point in the history
Response.status -> Reponse.status_code
Response.success -> Response.ok
Response.content -> Response.text
  • Loading branch information
pat-dill committed May 18, 2020
1 parent 3b4c5d5 commit 90422c3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 66 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.

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.
## 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

## [Documentation](https://jpatrickdill.github.io/roblox-requests/guide/installation/)

[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
46 changes: 26 additions & 20 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
# Roblox Requests {{ version }}
# Roblox Requests

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

---

An example of what you can do with Requests:
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.

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.

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.
## Roblox Requests 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
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
10 changes: 0 additions & 10 deletions rojo.json

This file was deleted.

0 comments on commit 90422c3

Please sign in to comment.