Skip to content

Instantly share code, notes, and snippets.

View featherart's full-sized avatar
🎯
Focusing

Feather featherart

🎯
Focusing
View GitHub Profile
@featherart
featherart / gist:e092df4a973108fa5598f9743b4198d4
Last active August 31, 2020 18:22
generate a new todo context
# generate a new context Todos with a database table Items. This table will have fields
# description:string
# priority:string
# is_done:boolean
mix phx.gen.live Todos Item items description:string priority:string is_done:boolean
# scaffold the todos UI app
npx create-react-app todos-ui
# move into the newly created directory
cd todos-ui
# install all dependencies
yarn
# create a new todo item
curl -H "Content-Type: application/json" -X POST -d '{"item":{"description":"learn elixir", "priority":1, "is_complete": false }}' http://localhost:4000/api/items
# list items
curl -H "Content-Type: application/json" -X GET http://localhost:4000/api/items
# in dev.ex, under
config :todos_api ...
debug_errors: false,
...
# generate context & controller for a JSON resource
# this will create a migration that when run will create a table for items
# this table has a description, a priority level and a flag for whether the task is complete
mix phx.gen.json TodoItem Item items description:string priority:integer is_complete:boolean
# to run the migration we will use ecto again
mix ecto.migrate
# run all tests
mix test
# fire up the server
# by default the server will be listening on http://localhost:4000
mix phx.server
@featherart
featherart / gist:dee7af017b84f4733329176535f46c64
Last active February 5, 2020 05:39
Create a new JSON Phoenix API
# generate a new app in a directory called todos-json-api
# namespaced under ToDosApi, & no html or webpack will scaffolded
mix phx.new todos-json-api --app todos_api --module ToDosApi --no-html --no-webpack
# go into newly created directory
cd todos-json-api
# create the database
mix ecto.create
# To install postgres
brew update
brew install postgres
# To create new user (necessary step before you can create a database):
createuser -d postgres
# To start up postgres:
brew services start postgresql
@featherart
featherart / .block
Created November 10, 2017 03:06
fresh block
license: mit
@featherart
featherart / .block
Last active November 10, 2017 02:44
fresh block
license: mit