Skip to content

mekanoe/clienthttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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" /> 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

let fetch

API.onResourceStart.connect(() => {
	const { require } = exported.require.require

	fetch = require('clienthttp').fetch

	fetch('https://httpbin.org/user-agent').then((response) => {
		return response.json()
	}).then((data) => {
		API.sendChatMessage(`The your user agent is ${data['user-agent']}`)
	})
})

Example, without require

let fetch

API.onResourceStart.connect(() => {
	fetch = exported.clienthttp.clienthttp.fetch

	fetch('https://httpbin.org/user-agent').then((response) => {
		return response.json()
	}).then((data) => {
		API.sendChatMessage(`The your user agent is ${data['user-agent']}`)
	})
})

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.

About

GTA: Network client-side HTTP client

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published