Public Chat API
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"},
{:kino_db, "~> 0.2.1"},
{:httpoison, "~> 2.1.0"}
])
Navigation
Public Chat API
We have created a public chat application you can visit in your browser.
To chat on this chat application users need to make a HTTP POST request.
Use HTTPoison.post/3 to send a message to the chat API.
The HTTP POST body should be a JSON string with a “body” field. i.e. "{\"body\": \"hello!\"}"
.
The HTTP POST headers should include the Content-Type
field to specify that the data being sent is JSON.
Ensure that your message appears on the chat application.
HTTPoison.post("http://localhost:4000", "{\"body\": \"hello!\"}", [
{"Content-Type", "application/json"}
])
Mark As Completed
file_name = Path.basename(Regex.replace(~r/#.+/, __ENV__.file, ""), ".livemd")
progress_path = __DIR__ <> "/../progress.json"
existing_progress = File.read!(progress_path) |> Jason.decode!()
default = Map.get(existing_progress, file_name, false)
form =
Kino.Control.form(
[
completed: input = Kino.Input.checkbox("Mark As Completed", default: default)
],
report_changes: true
)
Task.async(fn ->
for %{data: %{completed: completed}} <- Kino.Control.stream(form) do
File.write!(progress_path, Jason.encode!(Map.put(existing_progress, file_name, completed)))
end
end)
form
Commit Your Progress
Run the following in your command line from the curriculum folder to track and save your progress in a Git commit.
Ensure that you do not already have undesired or unrelated changes by running git status
or by checking the source control tab in Visual Studio Code.
$ git checkout solutions
$ git checkout -b public-chat-api-exercise
$ git add .
$ git commit -m "finish public chat api exercise"
$ git push origin public-chat-api-exercise
Create a pull request from your public-chat-api-exercise
branch to your solutions
branch.
Please do not create a pull request to the DockYard Academy repository as this will spam our PR tracker.
DockYard Academy Students Only:
Notify your instructor by including @BrooklinJazz
in your PR description to get feedback.
You (or your instructor) may merge your PR into your solutions branch after review.
If you are interested in joining the next academy cohort, sign up here to receive more news when it is available.