links: [[Phoenix MOC]]
---
# Generate Api along with html
If you have generated html using *phx.gen* and want to add api also, you can do something like this
To generate *html*
```sh
mix phx.gen.html Accounts User users email:string hashed_password: string
```
Now to generate json
```sh
mix phx.gen.json Accounts User users email:string hashed_password: string --web Api --no-context --no-schema
```
Here we are creating new namespace called *Api* using --web flag and we are skipping context and schema creation, as they are already created during html generation
The last missing piece was to route Api. open *routex.ex*
Add Context as YourAppName.Api and process as api
```elixir
scope "/api", KancheWeb.Api, as: :api do
pipe_through :api
resources "/users", UserController
end
```
---
tags: #cli, #generator
source:
- [https://www.kickinespresso.com/posts/generating-html-and-json-scaffold-with-phoenix-1-3-1-3-2-generorators](scaffold html and json using phoenix generators via cli)