# How can we create new REST API

**URL:** <https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433>\
**Category:** Development\
**Tags:** webservices, restws, openmrs, rest\
**Created:** [March 1, 2021, 2:13pm UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433 "2021-03-01T14:13:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![narukumar](https://talk.openmrs.org/letter_avatar/narukumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@narukumar](https://talk.openmrs.org/u/narukumar)\
**Post date:** [March 1, 2021, 2:13pm UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/1 "2021-03-01T14:13:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![medhavi](https://talk.openmrs.org/user_avatar/talk.openmrs.org/medhavi/32/14684_2.png) [@medhavi](https://talk.openmrs.org/u/medhavi)\
**Post date:** [March 1, 2021, 3:38pm UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/2 "2021-03-01T15:38:17Z")

</div>

@narukumar You can follow this [link](https://wiki.openmrs.org/display/docs/Adding+a+Web+Service+Step+by+Step+Guide+for+Module+Developers). You can easily setup a new REST endpoint with the help of webservices.rest module.

---

<div class="post-metadata">

**Author:** ![narukumar](https://talk.openmrs.org/letter_avatar/narukumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@narukumar](https://talk.openmrs.org/u/narukumar)\
**Post date:** [March 3, 2021, 11:24am UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/3 "2021-03-03T11:24:40Z")

</div>

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](https://pastebin.com/XnDHTrGM) . 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.

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [March 3, 2021, 11:35am UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/4 "2021-03-03T11:35:07Z")

</div>

> [@narukumar](#):
>
> 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](https://pastebin.com/XnDHTrGM) . 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

---

<div class="post-metadata">

**Author:** ![medhavi](https://talk.openmrs.org/user_avatar/talk.openmrs.org/medhavi/32/14684_2.png) [@medhavi](https://talk.openmrs.org/u/medhavi)\
**Post date:** [March 3, 2021, 12:57pm UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/5 "2021-03-03T12:57:12Z")

</div>

@narukumar you can paste your log [https://pastebin.com/](https://pastebin.com/) here.

---

<div class="post-metadata">

**Author:** ![narukumar](https://talk.openmrs.org/letter_avatar/narukumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@narukumar](https://talk.openmrs.org/u/narukumar)\
**Post date:** [March 3, 2021, 1:09pm UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/6 "2021-03-03T13:09:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![medhavi](https://talk.openmrs.org/user_avatar/talk.openmrs.org/medhavi/32/14684_2.png) [@medhavi](https://talk.openmrs.org/u/medhavi)\
**Post date:** [March 3, 2021, 1:21pm UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/7 "2021-03-03T13:21:03Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![theanandankit](https://talk.openmrs.org/user_avatar/talk.openmrs.org/theanandankit/32/15903_2.png) [@theanandankit](https://talk.openmrs.org/u/theanandankit)\
**Post date:** [March 3, 2021, 2:04pm UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/8 "2021-03-03T14:04:39Z")

</div>

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

> @RequestMapping` `(` `“/rest/”` `+ RestConstants.VERSION\_1 + ` `“/yourmoduleid”` `)

---

<div class="post-metadata">

**Author:** ![narukumar](https://talk.openmrs.org/letter_avatar/narukumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@narukumar](https://talk.openmrs.org/u/narukumar)\
**Post date:** [March 4, 2021, 5:45am UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/9 "2021-03-04T05:45:52Z")

</div>

> [@gcliff](#):
>
> Could you share the endpoint you are trying to call

I have created [this](https://pastebin.com/bQS0NxzY) controller class, and trying to call this by url “[http://localhost:8080/openmrs/ws/rest/v1/demo](http://localhost:8080/openmrs/ws/rest/v1/demo)”

---

<div class="post-metadata">

**Author:** ![gcliff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/gcliff/32/8783_2.png) [@gcliff](https://talk.openmrs.org/u/gcliff)\
**Post date:** [March 4, 2021, 6:04am UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/10 "2021-03-04T06:04:27Z")

</div>

> [@narukumar](#):
>
> “[http://localhost:8080/openmrs/ws/rest/v1/demo”](http://localhost:8080/openmrs/ws/rest/v1/demo%E2%80%9D)

there is no such end point in the rest api

kindly look into this [OpenMRS Docs](https://rest.openmrs.org/#openmrs-rest-api)

---

<div class="post-metadata">

**Author:** ![narukumar](https://talk.openmrs.org/letter_avatar/narukumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@narukumar](https://talk.openmrs.org/u/narukumar)\
**Post date:** [March 4, 2021, 7:32am UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/11 "2021-03-04T07:32:20Z")

</div>

@medhavi and @gcliffI have created [this](https://pastebin.com/bQS0NxzY) controller class, and trying to call this by url “[http://localhost:8080/openmrs/ws/rest/v1/demo](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](https://pastebin.com/bQS0NxzY) 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.

---

<div class="post-metadata">

**Author:** ![narukumar](https://talk.openmrs.org/letter_avatar/narukumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@narukumar](https://talk.openmrs.org/u/narukumar)\
**Post date:** [March 4, 2021, 7:35am UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/12 "2021-03-04T07:35:02Z")

</div>

can we create our custom endpoint in rest api?

---

<div class="post-metadata">

**Author:** ![theanandankit](https://talk.openmrs.org/user_avatar/talk.openmrs.org/theanandankit/32/15903_2.png) [@theanandankit](https://talk.openmrs.org/u/theanandankit)\
**Post date:** [March 4, 2021, 7:50am UTC](https://talk.openmrs.org/t/how-can-we-create-new-rest-api/32433/13 "2021-03-04T07:50:45Z")

</div>

@narukumar you can see [this](https://github.com/openmrs/openmrs-module-smartonfhir/pull/11/commits/2d49b8f79766816a7751eadfe1a665fc2e95e25f) commit. Once i created the custom endpoint. may this will help and let me know if you face any issue.
