mattn / webapi-vim

vim interface to Web API
http://www.vim.org/scripts/script.php?script_id=4019
684 stars 61 forks source link

support for async http in vim 8 and neovim #29

Open prabirshrestha opened 7 years ago

prabirshrestha commented 7 years ago

Would like to support searching packages online for npmjs.org, cdnjs and hopefully integrate with ctrlp when it supports async.

prabirshrestha commented 7 years ago

Seems to be now supported in vim8 using webapi#http#stream. Doesn't work in neovim since it uses vim8 job apis.

function! s:callback(type, req, data) abort
    if a:type == 'out'
        let a:req['buffer'] = a:req['buffer'] . a:data
    elseif a:type == 'exit'
        let res = a:req['buffer']
        echom res
    endif
endfunction

let req = {
    \ 'url': 'https://httpbin.org/get',
    \ 'method': 'GET',
    \ 'buffer': '',
    \ }
let req['out_cb'] = function('s:callback', ['out', req])
let req['exit_cb'] = function('s:callback', ['exit', req])
call webapi#http#stream(req)

Any plans to expose http status code as well as headers here?

mattn commented 7 years ago

I'm not familier to neovim. Anyone please send me pull-request.