Git Product home page Git Product logo

roxios's Introduction

roxios

Roxios is a simple, fast, and powerful HttpService wrapper for Roblox, with a focus on mocking the current API in a promise-based format for easy integration into current codebase with little-to-no learning curve.

https://github.com/FxllenCode/roxios/

Roxios was insipired by Axios!

Getting Started

Option 1 - With Wally (Recommended)

To install via Wally, add the following to your wally.toml file:

[dependencies]
roxios = "fxllencode/[email protected]"

Then, run wally install to install the dependencies.

Option 2 - With .rbxm

You can also drag and drop roxios directly into your project, under ReplicatedStorage.

Head to the releases page to download the latest version, and drag pack.rbxm into ReplicatedStorage.

Option 3 - Building from Source Code with Foreman

If you wish, you can also download the source code and build it yourself. In order for this option to work, you must have Foreman installed.

Firstly, clone the repository:

git clone https://github.com/FxllenCode/roxios.git

Then, enter the directory you created. With Foreman, run:

foreman install

to install the required tools.

Then, run: wally install to install the dependencies.

Finally, build the .rbxm file:

rojo build -o pack.rbxm pack.project.json

Testing a sample project

roxios includes a sample project for your convience. To run, first clone the repository:

git clone https://github.com/FxllenCode/roxios.git

Then, enter the directory you created. With Foreman, run:

foreman install

to install the required tools.

Then, run: wally install to install the dependencies.

Finally, serve the project via Rojo:

rojo serve testing.project.json

Ensure you connect via Roblox Studio, and hit run!

Usage

roxios is not intended to be a major difference from most other HttpService wrappers. However, it is a bit more powerful, and has a few additional features.

Firstly, it uses the promise library to make it easier to work with responses and errors. I suggest you check out the documentation for a full list of features, however to sum it up, you call the function, and then use :andThen() to handle the response, or :catch() to handle errors.

local function myFunction()
    return Promise.new(function(resolve, reject, onCancel)
        somethingThatYields()
        resolve("Hello world!")
        if !somethingThatDoesNotYield() then
            reject("Something went wrong!")
        end
    end)
end

myFunction():andThen(print):catch(print)

Secondly, it has a mock-example of HttpRbxApiService, which is nearly identical to HttpService, however, it can make requests to the Roblox API, which HttpService cannot do without a proxy. For your convince, there is a function called RbxApiRequest(options), which is essentially a mock of HttpService:RequestAsync(options), however it returns a promise, and uses a proxy.

However, you shouldn't use this in production! There are a multitude of reasons as to why you should not use this, and I will not go into them here. Feel free to continue reading below:

https://devforum.roblox.com/t/psa-stop-using-roblox-proxies/1573256

API

roxios.Request(options: Options)

Returns: A promise, which resolves to parsedResponse, rawResponse, or rejects with an error.

roxios.Get(url: string, noCache: boolean?, headers: any?)

  • url: The url to request.

  • noCache: Whether or not to use the cache.

  • headers: Any headers to pass to the request.

Returns: A promise, which resolves to parsedResponse, rawResponse, or rejects with an error.

roxios.Post(url: string, json: string, content_type: Enum.HttpContentType?, compress: boolean?, headers: any?)

  • url: The url to request.

  • json: The json to send.

  • content_type: The content type to request back.

  • compress: Whether or not to compress the request.

  • headers: Any headers to pass to the request.

Returns: A promise, which resolves to parsedResponse, rawResponse, or rejects with an error.

roxios.RbxApiRequest(options: Options)

Returns: A promise, which resolves to parsedResponse, rawResponse, or rejects with an error.

Example

local roxios = require(game.ReplicatedStorage.roxios)
local HttpService = game:GetService("HttpService")
roxios.Request({
	Url = "http://httpbin.org/post",
	Method = "POST",
	Headers = {
		["Content-Type"] = "application/json",
	},
	Body = HttpService:JSONEncode({ hello = "world" }),
})
	:andThen(function(parsedResponse)
		print(parsedResponse.data)
	end)
	:catch(function(error)
		warn(error)
	end)

roxios.Get("http://httpbin.org/get", true)
	:andThen(function(parsedResponse)
		print(parsedResponse)
	end)
	:catch(function(error)
		warn(error)
	end)

roxios.Post(
	"https://httpbin.org/post",
	HttpService:JSONEncode({ hello = "world" }),
	Enum.HttpContentType.ApplicationJson,
	false
)
	:andThen(function(parsedResponse)
		print(parsedResponse.data)
	end)
	:catch(function(error)
		warn(error)
	end)

roxios.RbxApiRequest({
	Url = "http://setup.roblox.com/version",
	Method = "GET",
	Headers = {
		["Content-Type"] = "application/json",
	},
})
	:andThen(function(_, response)
		print(response)
	end)
	:catch(function(error)
		warn(error)
	end)

Contributing

This project uses Foreman to install all toolchains. If you wish to contribute, please fork the repository, and build the project yourself. Make sure you run selene and stylua before committing any changes, other wise CI may fail.

Please ensure you have tested code before committing. If you have any issues, please open an issue on the Github repository.

Make sure you have updated the version in wally.toml to the latest SemVer.

License

roxios is available under the terms of the MIT License. Terms and conditions are available in LICENSE.txt or at https://opensource.org/licenses/MIT.

roxios's People

Contributors

fxllencode avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.