Post api request is changing route on frontend to api route.

I have a form that makes a post request which works fine but it is changing the route in front-end to the API route.

In router

 post "/blogs", BlogController, :create

In HTML form

<%= form_for @conn, Routes.blog_path(@conn, :create), [multipart: true], fn f -> %>
  <label>
    Title: <%= text_input f, :title %>
  </label>
  <label>
    Type: <%= select f, :type, [
    "Blog": "blog", 
    "Email": "email",
    "Bot Builder": "Bot Builder", 
    "Appointments": "appointments"] %>
  </label>
<label>
    Sub Title: <%= text_input f, :sub_title %>
  </label>
  <label>
    Author: <%= text_input f, :author %>
  </label>
 <label>
     Image URL: <%= text_input f, :URL %>
  </label>
 <label>
     File: <%= file_input f, :photo %>
  </label>
  <%= submit "Submit" %>
<% end %>

In Controller

def create(conn, blog_params) do
    with {:ok, %Blog{} = blog} <- BlogCatalog.create_blog(blog_params) do
      conn
      |> put_status(:created)
      |> render("show.json", blog: blog)
    end
  end

Before submitting the form URL: (http://localhost:4000/)
After submitting the URL in the frontend is http://localhost:4000/api/blogs

I want to stay on the same page on f.e

Thanks.

Hi @sagarmounika welcome. I have edited your post to use code blocks, please use those in the future so that your posts are easy to read.

You’re rendering “show.json” here, which is probably why it’s showing JSON. You probably also want to redirect back to the page you were on instead of calling render.

Thank you for your quick response.
Sorry, I am new to Elixir. but is there any way without redirecting? Should I just make an API request on button click instead of using Routes.blog_path.