Code Monkey home page Code Monkey logo

netas's Introduction

netas

The library that netas uses to send network requests, It can work in both browser and node environment, and their usage is the same

install

Using npm

$ npm install netas

use

in Node.js

// import netas
var netas = require('netas')

// Just configure the URL
var config = {
  url: 'http://registry.npmjs.org/netas',
}

// use netas.request
netas.request(config).then(function (res) {
  // pass
}, function (err) {
  // pass
})

upload file

if you need to upload single file

var path = require('path')
var netas = require('netas')
var File = require('netas/File')


var config = {
  method: 'post',
  dataType:"multipart",
  url: 'url',
  data: {file:new File(path.join(__dirname, './test.txt')) }
}

netas.request(config).then(function (res) {
  // pass
}, function (err) {
  // pass
})

files

var path = require('path')
var netas = require('netas')
// import FormData and File ( in node )
var FormData = require('netas/FormData')
var File = require('netas/File')


var fd = new FormData
fd.append('file', new File(path.join(__dirname, './test.txt')))
fd.append('file', new File(path.join(__dirname, './test2.txt')))


var config = {
  method: 'post',
  url: 'url',
  data: fd
}

netas.request(config).then(function (res) {
  // pass
}, function (err) {
  // pass
})

in Web

var netas  = require('netas/web')

var config = {
    url:'url'
}

netas.request(config).then(res=>{
  // pass
},(err)=>{
  // pass
})

config

  • baseUrl

    The default request address, which will be spliced with the URL.

    type: string

    default: ''

  • headers

    Request header

    type: object

    default: {}

  • data

    Request volume data

    type: FormData | object

    default: {}

  • cache

    Turn on HTTP weak cache

    type: boolean

    default: true

  • params

    Query parameter

    type: object

    default: {}

  • dataType

    Request volume data type

    string: 'json' | 'multipart' | ''

    default: 'json'

  • method

    HTTP request methods.

    string: 'get' | 'post' | 'put' | 'options' | 'delete' | 'patch' | 'connect' | 'trace' | 'head'

    default: 'get'

  • timeout

    The timeout of Ajax

    type: number

    default: 1000 * 10

  • responseType

    Returns the type of data

    string: 'json' | 'text' | 'binary'

    default: 'json'

Note:

Netas doesn't test too much, it may still have bugs .

Please choose the latest version first, others may have bugs .

netas's People

Contributors

liaoqinwei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.