Giter Club home page Giter Club logo

gd-rpc's Introduction

gd-rpc-threaded

Threaded Web requests in GDScript for Godot game engine.

Installation

rpc-threaded and rpcresponse are GDScripts, so all you need is to drop them into your Godot project's resource directory. rpc-threaded inherits from Node and is to be added to your node-tree, rpcresponse is a standalone class inherits from built-in type.

Use

rpc

var RPC = preload("rpc.gd")
var www

func _init():
    www = RPC.new() # use "localhost", on port 80
    # or for "http://myhost.example:1234":
    www = RPC.new("myhost.example", 1234)

func _ready():
    add_child(www)  # NOTE: It's important to add rpc as a node to your tree

By default, the www object has a user-agent header set. You may set your own headers. This is done separate from any actual request.

# remove user agent
www.resetHeaders()

# set one header
www.setHeader("Authorization", authToken)

# set many headers
www.setHeaders({
    "Accept": "*",
    "Content-Type": "application/json"
})

With host, port, and headers configured, make your HTTP request.

r = www.get("/users")
r = www.post("/ratings/" + id, '{"rating":4,"review":"ok"}')
r = www.delete("/reviews/12")

rpcresponse

Every request (using get, post, put, delete) returns a RpcResponse object, a data container with the response's HTTP Status code, body, and headers. Check for errors before assuming all went well;

response = www.get("/something")
if( response.isError() ):
    handleError( response.getResponseCode() )
else:
    handleSuccess( response.getBody() )

#TODO

  • Optional form encoding for http-post
  • Optional url encoding for http-get param dictionaries
  • SSL support
  • support for binaries and bigger files (chunked get/post)
  • handle Redirects

Contributing

Please, if you have a feature you'd like to have added, create an issue on github or send a pull request.

gd-rpc's People

Contributors

andi-k avatar bibby avatar drtwisted avatar toger5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gd-rpc's Issues

It would be cool to also support an async request.

I would basically just put the while loop In your _poll function into a different thread and than add an event to the class. which gets triggered after receiving data.
or you could even add another function argument. (although I don't know if that makes sense. as far as I know Godot doesn't support any closer type syntax sugar...)

godot 1.1

it raise an error in rpg.gd in godot 1.1
var RPC = preload("rpc.gd");

when I change it to get_script() it will raise another error saying
cannot access self without instance

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.