dwyl/phoenix-todo-list-tutorial

Feat: Todo List `REST API`

nelsonic opened this issue ยท 2 comments

Once deployed to Fly.io with CI/CD #52 and auth is added #37
we should add a basic REST API endpoint to CRUD Todo List items.

Why?

As part of building a full-stack App using our chosen Tech Stack https://github.com/dwyl/technology-stack#the-petal-stack
We want to build the backend API in Phoenix.
This mini tutorial is the perfect place to showcase building such an API because all the ground-work is already done for Todo list items.

Todo

  • in the same Phoenix App, create a new api_controller.ex for CRUD-ing the Todo list items (you can use :pipe_through :json).

    Remember our objective is to leverage as much of the existing work in this repo as possible. ๐Ÿ™

  • Create an API Endpoint for Creating a new todo list item and test it via cURL (or Postman)
    • Should accept a JSON payload with the necessary data, e.g:
    1. person_id (Int)
    2. status (Int)
    3. text (String)

schema "items" do
field :person_id, :integer, default: 0
field :status, :integer, default: 0
field :text, :string

  • Should create a new Todo item if the data is valid

  • Create a REST API Endpoint for editing the Todo list item.text:

    • Signature: POST /items/:id/
    • Should accept the item.id (Int) and item.text (String) and return 200 if successful. ๐Ÿ†—
  • Create REST API Endpoint for Updating the status of the item i.e. setting it to "done" โœ…

Relevant Learning

Please read: https://github.com/dwyl/phoenix-content-negotiation-tutorial ๐Ÿ‘€
And if you have any questions regarding content negotiation please open an issue. ๐Ÿ†•

For this project we don't need to have all the same routes we just need:

  1. Create ๐Ÿ†•
  2. Edit ๐Ÿ“
  3. Update status โœ…

@LuchoTurtle assigning this to you. But if anything is unclear please comment. ๐Ÿ’ฌ ๐Ÿ™

@LuchoTurtle please see: dwyl/hits#168 ๐Ÿ”—