jsonapi
jsonapi copied to clipboard
Phoenix Generators
I think it would be great to get some phoenix generators in here. This is my "best case" api
mix jsonapi.gen.resource User users name:string email:string bio:string number_of_pets:integer
* creating priv/repo/migrations/20150409213440_create_user.exs
* creating web/models/user.ex
* creating test/models/user_test.exs
* creating web/controllers/user_controller.ex
* creating web/views/user_view.ex
* creating test/controllers/user_controller_test.exs
Add the resource to your browser scope in web/router.ex:
resources "/users", UserController
and then update your repository by running migrations:
$ mix ecto.migrate
And then
mix jsonapi.gen.resource Post posts title:string body:string belongs_to:User
* creating priv/repo/migrations/20150409213440_create_post.exs
* creating web/models/post.ex
* creating test/models/post_test.exs
* creating web/controllers/post_controller.ex
* creating web/views/post_view.ex
* creating test/controllers/post_controller_test.exs
Add the resource to your browser scope in web/router.ex:
resources "/posts", PostController
#TODO Figure out all the different LINKS routes we can insert here
and then update your repository by running migrations:
$ mix ecto.migrate
Then you could do a
GET /posts?include=user&fields=title,body,user.name&order=-posts.created_at
And it would work out of the box.
@jeregrine / @jherdman / @snewcomer is this still something we'd like to consider? If not, I vote we close the issue so we can keep things focused.
I think it could be kind of nice to do this. I don't think they're a must, but it'd certainly make it easier for new users to get started.
Something to consider, not something I'm willing to put time into, if someone else is :+1:
On Thu, Jan 31, 2019 at 3:13 PM James Herdman [email protected] wrote:
I think it could be kind of nice to do this. I don't think they're a must, but it'd certainly make it easier for new users to get started.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jeregrine/jsonapi/issues/21#issuecomment-459508554, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGKFktkehMr3cPWW_5XWle7SwVPrlBVks5vI1yKgaJpZM4G3ph1 .
Switching over a project soon, so I'll see if I can provide some unique insight!
Awesome feedback! I don't personally use the generators and have found maintaining them to be a tad bit a pain over time (we've got generators here: https://github.com/slime-lang/phoenix_slime).
That said if someone wants to do the work and maintain them as things change with Ecto, Phoenix, etc then we should keep this open 👍