shahryarjb

shahryarjb

Basic questions of creating a real time api for mobile developer

Hello, I have read this page, and some video which wanted to create a real time chat in a web page with Phoenix channel help. But I never realized some things that are very basic and important.

question one:

when I just need to create a api for mobile developer, do I need to know js and write js for my project ? because I want to create a api, not html render?

question two:

if I don’t need js please tell me how to test my api which is created by websocket like postman app for json api.

question three:

I just found a lib for Mac Terminal that it’s name is wscat, but after some second it is terminated, and I cant test more than it.

I found heartbeats or there was something, that Kept my connection a live, but I didn’t find something more than it

at last, I think Phoenix channel is like elixir GenServer, but I can’t start and test a api to learn it, and this is a problem I have no easy sampel code to create a api just this not more.

if you have a code that Handles easy task like a registration user Api and how to test with some soft in mac or terminal not a mobile app, please give me and help me

Thanks

Most Liked

LostKobrakai

LostKobrakai

Using channels without js simply means you need an implementation of phoenix.js for your mobile app. Phoenix channels are not just raw websockets, but a communication protocol on top of many transports – websockets being one of them. Therefore your app needs to be able to communicate using that protocol. In detail this means being able to negotiate a serialization protocol for messages. Being able to serialize/deserialize messages according to said protocol, understanding a handful of channel specific messages as well as dealing with all the app specific messages. Then you’ll need facilities for handling channel joins/connection, dealing with replys and such. And if you need it (and it sounds like you do) you also need to deal with presence messages and the diffing mechanism.

As for tracking connectivity. Websocket connections will terminate once disconnected, but especially for flaky network this can be unrelyable for detecting disconnects. Therefore there are heartbeats as part of phoenix channels. I’m not sure currently if there’re initiated by the client or by the server though, but it’s likely the client.

hauleth

hauleth

No, if there is no web UI then you do not need to care.

Write tests. There are also CLI tools for connecting to WS.

You need not only to connect to WS, but you also need to talk proper protocol, in this case Phoenix protocol defined in Phoenix.Socket.V2.JSONSerializer.

For testing channels you can use Phoenix.ChannelTest helpers.

outlog

outlog

if you search for heartbeat in that repo it’s there Repository search results · GitHub
I assume it’s handled automatically..

I haven’t done anything in swift but there is an example project there https://github.com/davidstump/SwiftPhoenixClient/tree/master/Example/ChatExample with specific code here:

https://github.com/davidstump/SwiftPhoenixClient/blob/master/Example/ChatExample/ViewController.swift

Where Next?

Popular in Discussions Top

jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
Donovan
Hello everyone, I’m so glad to have discovered this awesome community. Thanks for creating it! This is my second post, and apologies for...
New
Jayshua
I recently came across the javascript library htmx. It reminded me a lot of liveview so I thought the community here might be interested....
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
jeramyRR
This is an interesting article to read. Elixir’s performance, like usual, is excellent. However, it seems like the high CPU usage is co...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 13924 124
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18146 126
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement