0
votes

I have been fllowing a code from https://medium.freecodecamp.org/how-to-write-a-super-fast-link-shortener-with-elixir-phoenix-and-mnesia-70ffa1564b3c to write a url shortener as a means to learn elixir and phoenix .

Whenever I launch my phoenix server on the localhost:4000 it gives this error:

"Phoenix.Router.NoRouteError at GET / no route found for GET / (ShortenApiWeb.Router) "

Furthermore the terminal says that the way for the live reloading web socket is not also defined:

[info] GET /phoenix/live_reload/socket/websocket
[debug] ** (Phoenix.Router.NoRouteError) no route found for GET /phoenix/live_reload/socket/websocket (ShortenApiWeb.Router)

.

1

1 Answers

0
votes

It gives you error because project does not have anything binded to / route.

You have to create your links using curl

curl --request POST \
  --url http://localhost:4000/api/links/ \
  --header 'content-type: application/json' \
  --data '{
 "link": {
  "url": "https://twitter.com/bnchrch"
 }
}'

And after that you will be able to open it into browser using hash (you should receive it as curl response. Something like {"data":{"url":"https://twitter.com/bnchrch","hash":"Aode7DEz"}}

Now you could open http://localhost:4000/Aode7DEz and it will redirect you to URL you sent.