Websockets vs HTTP for REST API

Whats the difference and when to use which?

Other urls found in this thread:

npmjs.com/package/websocket
pypi.python.org/pypi/websockets
socketo.me/
github.com/faye/faye-websocket-ruby
github.com/zaphoyd/websocketpp
lmddgtfy.net/?q=websocket library
discord.gg/B9pWAhr
twitter.com/NSFWRedditGif

Websockets allow you to keep a persistent connection between the client and server. Overkill for REST though. Use them when you would otherwise need to poll.

The entire idea behind REST APIs is to use the standardized HTTP verbs.

> (OP)
>Websockets allow you to keep a persistent connection between the client and server. Overkill for REST though. Use them when you would otherwise need to poll.

What's the difference with HTTP/2?

HTTP2 just allows all of the page content to be loaded with a single connection, instead of one for each resource, it still terminates when the page is done loading.

Websockets allow a backchannel from the server to the client, so if the server needs to notify the client of something (eg. notifications) that's what you'd want to use. Otherwise you'd have to have the client poll which puts more load on the server.

>Whats the difference and when to use which?
both shit
just make your own protocol over TCP

> TCP
> Not writing your own transport layer

If the client is expected to make a lot of request: websockets.

If not, http.

How much is "a lot" per client?

Look, my project is crypto related, and I will be making a few thousand requests per minute. I will have a lot of live changes, so I will need to use AJAX or Websockets secure in order to sync the site files with the backend data. I need the fastest possible, so I may use HTTP/2 although i dont think that is widely supported

You probably want websockets then. AJAX will turn your server into a toaster

Web3.0 cancer. I make the request if I want to, not the server

i dont know how to run a rest server. how do u do that.

*correction
i was meaning to say a websocket server that gets requests from a javascript script and then returns json code via rest.

Use one of the dozen websocket libraries for whatever platform you're writing the server in.

npmjs.com/package/websocket
pypi.python.org/pypi/websockets
socketo.me/
github.com/faye/faye-websocket-ruby
github.com/zaphoyd/websocketpp
lmddgtfy.net/?q=websocket library

The client still has to start the websocket connection and can kill it whenever they want. Before websockets it was polling or Flash for web IM (IRC is better though)

how do u serve it tho like have the server respond to the requests. do i connect it to something like wangle or poco or asio, and if so, do u have any tutorials about it? i am doing c++

Either run a standalone Websocket server on a subdomain or with a reverse proxy (eg. nginx), or use whatever websocket support your http server has. lighttpd has a mod_websocket, apache probably has something similar.

would the websocket module in poco work

Should be able to.

how should the authentication and security work? do i use wss and oauth2 (wait isnt that http and rest only????)

Have the client do a normal REST OAuth2 authentication before opening the socket, then once they open the socket, send the token over it to authenticate it

Do you think android and ios apps could use websockets. i dont think apple would support such a thing in apps, but idk. they have json

Android, iOS, and desktop apps can use websockets natively just fine and Apple doesn't care.

do you have a discord? i think we should talk more about websockets. my project is a cryptocurency exchange (no shitcoins)

well anyways if you have one mine is discord.gg/B9pWAhr

its always sad to see old threads die. rip. also, ws >>>>>>> http for performance