Skip to content

JairusSW/as-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

As-HTTP

HTTP Client For AssemblyScript

Features

  • Uses Fetch in NodeJS and Web
  • Handles Headers
  • Get/Post Support
  • Http/1.1

Setting up

Add --exportTable and --exportRuntime flags

+ const HTTPimports = require('as-http')

+ const http = new HTTPimports()

const imports = {
+    ...http.wasmImports
}

const wasmModule = loader.instantaniateSync()

+ http.wasmExports = wasmModule.exports

Usage

GET Request

import { http } from 'as-http'

const headers = new Map<string, string>()

headers.set('token', 'GqC2F-e[.2,s</01kdFw')
//--> Add/Edit any header

http.get('http://example.com/', headers, (error, body) => {

    console.log('Response: ' + body)

})

POST Request

import { http } from 'as-http'

const headers = new Map<string, string>()

headers.set('token', 'GqC2F-e[.2,s</01kdFw')
//--> Add/Edit any header

const data = 'Hello, Server!'
//--> Add data chunk (Multipart coming soon)

http.post('http://example.com/', headers, data, (error, body) => {

    console.log('Response: ' + body)

})

Examples

Get a random joke

import { http } from 'as-http'

const headers = new Map<string, string>()

http.get('https://official-joke-api.appspot.com/random_joke', headers, (error, body) => {

    console.log('Response: ' + body)

})

Get youtube search results

import { http } from 'as-http'

const headers = new Map<string, string>()

const query = 'Marshmallow'

http.get(`https://youtubestream.jairussw.repl.co/search?query=${query}&limit=5`, headers, (error, body) => {

    console.log('Response: ' + body)

})

About

HTTP Client for AssemblyScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published