项目作者: kayteh

项目描述 :
GTA: Network client-side HTTP client
高级语言: JavaScript
项目地址: git://github.com/kayteh/clienthttp.git
创建时间: 2017-05-25T18:02:02Z
项目社区:https://github.com/kayteh/clienthttp

开源协议:MIT License

下载


clienthttp / fetch API for gta: network

“this is magic” - Nvw 2017

this resource provides a client-side code HTTP client for GTA: Network.

this does not supply you with an HTTP client on the server. use included C# tools. you may use this resource as a weak reference for doing this, though.

JavaScript Style Guide

Installing

  1. your game server must be running .NET 4.5 or newer.

  2. clone this repo into your server’s resources folder.

  3. add <resource src="clienthttp" ></resource> to your settings.xml

  4. optionally install require (it’s cool, i swear!)

  5. done!

Using

This closely, but not perfectly, follows the WHATWG Fetch API spec. There’s not a lot to cover that other widely-available documentation sources already don’t.

All of the documentation on how to use this function is here: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch

Example, using require

  1. let fetch
  2. API.onResourceStart.connect(() => {
  3. const { require } = exported.require.require
  4. fetch = require('clienthttp').fetch
  5. fetch('https://httpbin.org/user-agent').then((response) => {
  6. return response.json()
  7. }).then((data) => {
  8. API.sendChatMessage(`The your user agent is ${data['user-agent']}`)
  9. })
  10. })

Example, without require

  1. let fetch
  2. API.onResourceStart.connect(() => {
  3. fetch = exported.clienthttp.clienthttp.fetch
  4. fetch('https://httpbin.org/user-agent').then((response) => {
  5. return response.json()
  6. }).then((data) => {
  7. API.sendChatMessage(`The your user agent is ${data['user-agent']}`)
  8. })
  9. })

Local-mode CEF example

soon

Caveats

This resource only allows you to receive text or json data.

If you need XML, or any other, you can open a PR or write a conversion library from Response.text(). This is literally what the JSON return does.