Mix phx.gen.auth Json API routes

mix phx.gen.auth create complete auth system and works like mix phx.gen.html. In my case, i only need to create json APIs. Like, mix phx.gen.json. How can achieve this?
Is there is any option for that.

1 Like

Here are some examples
https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html

Change the controllers so they return json, change the routes to pipe through :api and delete the views?

1 Like

Did you tried mix phx.gen.auth with json response. I think mix phx.new will create new phoenix project only. mix phx.gen.auth will create auth system with htmls. Correct me if i wrong!

Yes, right. We can do that. But, is there is any option to do it directly through the mix task?

1 Like

Yes it will create new project but you need to pass something like this
mix phx.new project_name --no-webpack --no-html

But I understand your requirement. I don’t think there is a direct way to generate this in an existing project. But why do you need it? You can do it manually starting with schema, model and controller then render the json in view.

Yup, I can do it directly by manual. But, i was curious about mix phx.gen.auth. If there is no way do it by the help of mix phx.gen.auth. I’m going to do it manual. Thanks for your reply.

You need to make it manually as there is no option to specify You are using an api.

2 Likes

As an example, I actually did this successfully in this boilerplate repo. I hope it helps!

2 Likes