Socket
Book a DemoInstallSign in
Socket

as-http

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

as-http

Http Client For AssemblyScript

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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)

})

Keywords

http

FAQs

Package last updated on 21 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts