Difficulty in using Postman in view of timestamp in model/migration

api
json
controller
#1

Difficulty in using Postman in view of timestamp in model/migration

0 Likes

#2

Can you please elaborate on some of the details please.

Thank You.

0 Likes

#3

The json was generated with mix phx.gen.json, In PostMan GET() gets the data we added in the database for those the fields(example name and content), though we added data for inserted _at and updated_at also in the database.But for a POST request we get only “Phoenix.ActionClauseError”-no function clause matching in … controller.create/2.As Postman can be replaced with a front-end JS framework later, any help in this regard will be useful to many who want to try Phoenix Rest Services in place of Rest Services with NODE AND Express.With regards
madanasekaran

0 Likes

#4

The problem is not in Postman, the problem is an error in your Elixir code. To have an answer to your question, You need to provide (much) more information.

For example, which Elixir/Phoenix version, what You did, what is the error message (in full) and related code.

Here would be a minimal example of what You could have done…

$ mix phx.new koko --no-html --no-webpack
$ cd koko
$ mix ecto.create
$ mix phx.gen.json Accounts User users name:string age:integer
$ mix ecto migrate
$ mix phx.server

# tests with postman

So, what did You do, or which post did You follow?

1 Like

#5

Sir,
Elixir 1.8.1

Phoenix 1.4.3

Only official guide was followed.All the steps narrated above were followed to generate the code.

mix phx.gen.json Blog Post posts name:string content:string

was executed and route was added as under:

.resources "/posts", PostController, except: [:new, :edit]

Postman v 1.8.8 - Post to http://localhost:4000/api/posts. body of the request

{
	"name": "Visnu",
	"content": "Supreme God",
	"inserted_at": "04/14/2019",
	"updated_at" : "04/14/2019
}

error

(Phoenix.ActionClauseError) no function clause matching in FirstAppWeb.PostController.create/2

.........

(first_app) lib/first_app_web/endpoint.ex:1: FirstAppWeb.Endpoint.instrument/4

(phoenix) lib/phoenix/router.ex:275: Phoenix.Router.__call__/1

(first_app) lib/first_app_web/endpoint.ex:1: FirstAppWeb.Endpoint.plug_builder_call/2

(first_app) lib/plug/debugger.ex:122: FirstAppWeb.Endpoint."call (overridable 3)"/2

(first_app) lib/first_app_web/endpoint.ex:1: FirstAppWeb.Endpoint.call/2

(phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:33: Phoenix.Endpoint.Cowboy2Handler.init/2

(cowboy) /home/prasanna/phoenix-apps/first_app/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2

(cowboy) /home/prasanna/phoenix-apps/first_app/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3

(cowboy) /home/prasanna/phoenix-apps/first_app/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3

(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Even without inserted_at and updated_at POST did not work.

The code was mostly generated.The manual part was the only the mix commands and addition to the router as above and insertion of records using PGADMIN-III

Thanking You

madanasekaran

0 Likes

#6

Right at the beginning of the error message it complains that create/2 doesn’t exist (something like this). Ignoring for the moment that it should be there, it would be potentially informative to see all of the code of the FirstAppWeb.PostController module to see what is actually there.

The next stop would be to show all of the code in router.ex (the FirstAppWeb.Router module).

Please use code fences around your code.

0 Likes

#7

You should not set inserted_at and updated_at in postman, this should be managed for You. This will not help with your problem, but it’s good practice to let the system manage this.

As mentionned by the previous post, please show the files, because it might be a typo in any of your command that will generate wrong files.

0 Likes

#8

Thanks.Whether any sample/blog available using Curl or Postman to post data to Phoenix Rest Service?

0 Likes

#9

Maybe this one

https://www.guru99.com/postman-tutorial.html

But it is not related to Phoenix, it is just a http client, so any tuto should be good to go.

Also, if You want to test your API, it would be better to test it with ExUnit, because You only need to test once (or write test once if You prefer).

0 Likes