How can we create new REST API

I have created a local setup of openmrs enterprise v 2.3.2 I have created a new table in openmrs db, and want to retrive all data on basis of uuid by an REST API. I want to create a new controller and service that will use session factory and retrieve data using sql native query. How can I achieve this?

Thanks in advance

@narukumar You can follow this link. You can easily setup a new REST endpoint with the help of webservices.rest module.

1 Like

Thank you @medhavi for you help. I have created on module and created an endpoint, but I am not able to call that endpoint from any client and getting resource not found . Can you tell me what is the entry endpoint for openmrs and what is the entire API flow in openmrs.

Looking forward to hearing from you.

@narukumar the Resource doesnt exist means the resource your are trying to retrieve is not available in the rest api or probably the end point url is not right

The end point to fetch data should look look like this

>     > GET /ws/rest/v1/{resource name}
>     > GET /ws/rest/v1/{resource name}/{uuid}

Could you share the endpoint you are trying to call

1 Like

@narukumar you can paste your log https://pastebin.com/ here.

@medhavi If you look my last comment you will find that I did post “resource not found” logs in https://pastebin.com/

1 Like

@narukumar sorry i didn’t notice that. I think the problem is with endpoint. could you please share your complete url that you are trying to call?

1 Like

@narukumar please ensure that you are calling the correct endpoint as you mapped inside RequestMapping

@RequestMapping ( "/rest/" + RestConstants.VERSION_1 + “/yourmoduleid” )

1 Like

I have created this controller class, and trying to call this by url “http://localhost:8080/openmrs/ws/rest/v1/demo

there is no such end point in the rest api

kindly look into this OpenMRS Docs

1 Like

@medhavi and @gcliff I have created this controller class, and trying to call this by url “http://localhost:8080/openmrs/ws/rest/v1/demo

Let me clear this, First I have created a new maven {mymodule} module in webservice.rest module. In {mymodule} I have created this controller class in package org.openmrs.module.demo.web.controller.

I am not sure that how to design rest api in openmrs, please guide in api development.

can we create our custom endpoint in rest api?

@narukumar you can see this commit. Once i created the custom endpoint. may this will help and let me know if you face any issue.