How to return custom json response

How can i return custom json response to clients that consume my API ?

You can convert any python method into a method that handles your API calls.

Create a method in a python file in your custom app:


def ping():
  return 'pong'

Call that method from your client side:

  .then(r => r.json())
  .then(r => console.log(r.message)) // 'pong'

More at REST API

1 Like

Thanks for your reply. How can i add a response status with the json data ? 200, 201 400 etc …

def ping():
# some statement…
return {“response_status”:200,“data”:response}
return {“response_status”:404,“message”:“Data not found!”}

Thanks for your reply,
is there a way to trigger the frappe.throw function to return json DATA because if i wante to return error json response i need to cascad return from within the specific function the error occurred