Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gopher-js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gopher-js

A powerful, flexible JavaScript AJAX library

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

gopher-js

A JavaScript AJAX library with proxies

go.get('people').then(result => {
    
    // handle the result
    
}).catch(error => {
    
    // handle the error
    
})

Configuration

go.configure({
    onerror : handleError,
    onprogress : handleProgress,
    timeout : 10000,
    urlPrefix : '/rs'
});

Options

go.get('customers', {
    block : true,
    cache : false,
    content : 'json',
    headers : {
        'Accept-Encoding' : 'utf-8'
    },
    message : 'Getting customers...',
    silent : true,
    type : 'json'
})

Proxies

Gopher includes the ability to create proxies (much like RESTEasy)

let customerProxy = go.createProxy({
    path: '/customers',
    endpoints: {
        getAllCustomers: {},
        getCustomerWithId: {
            path: '/{id}',
            options: {
                cache: true
            }
        },
        saveCustomer: {
            method: 'post'
        }
    }
});

// call the proxy method 

customerProxy.getCustomerWithId({ id : 102 }).then (result => { /* ... */ });

// you can also call the method with just arguments
// they will be added sequentially, as specified in the path

customerProxy.getCustomerWithId(102).then(result => { /* ... */ });

Data Mappers

Data mappers provide serializers and deserializers for AJAX data. Mappers comprise of two methods: serialize and deserialize. Included are mappers for JSON, plain text, and XML.

let MyJSONMapper = {
    serialize: function(data) {
        return JSON.stringify(data);
    },
    deserialize: function(data) {
        return (data) ? JSON.parse(data) : null;
    }
};

// add the mapper to the registry

go.mappers.add('json', MyJSONMapper, [ 'application/json', 'text/json' ]);

Methods

go.get(url, options)

Performs a GET request on the specified URL

go.post(url, data, options)

Performs a POST request

go.put(url, data, options)

Performs a PUT request

go.del(url, options)

Performs a DELETE request

go.head(url, options)

Performs a HEAD request

go.fetch(url)

Fetches a resource relative to the current location

Keywords

FAQs

Package last updated on 02 Nov 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc