# Backend (REST)

In the Linx REST [plugin](https://youtu.be/QhDudwn1VYA) are two services that you can use to build REST APIs: [SimpleRESTHost (for most APIs)](https://docs.linx.software/reference/plugins/rest/content/simpleresthost) and [RESTHost (for advanced APIs)](https://docs.linx.software/reference/plugins/rest/content/resthost).

***

## Building a REST API with SimpleRESTHost

1. Open the Linx Designer and click **Create Solution**.
2. Click the **Add Plugins** button on the right to open the plugins popup.
3. In the Plugins popup, find the **REST** plugin in the list and click **ADD** (the initial download might take a moment). When the download is done, close the plugins popup.

   <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-2dfff4cef7c66647fac0dab143736c2ccfabfbf8%2Ffsro1.gif?alt=media" alt=""><figcaption></figcaption></figure>
4. Locate the **REST** plugin in the plugins panel. Find the **SimpleRESTHost** Service (it has a purple **SVC** prefix) and drag it into the **Solution Explorer panel** in the top left of your Designer.

   <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-db756e6d2a96bd446851c124f6ba9702d60b4b18%2Ffsro2.gif?alt=media" alt=""><figcaption></figcaption></figure>
5. Select the **SimpleRESTHost** in the Solution Explorer panel and locate the **Base URI** property in the Properties panel in the bottom left of the Designer. Enter this value into the property: **<http://localhost:8023>**.

   <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-620016161397ed5abb55ce672cd4a7232f9b2772%2Ffsro3.gif?alt=media" alt=""><figcaption></figcaption></figure>
6. Locate the **Operations** property of the **SimpleRESTHost** and click the **…** button in the field to open the Operations Editor to add API endpoints.
7. By default, Linx adds an operation called **Operation1**. Locate the **Path property** for Operation1 in the Operations popup.
8. Enter **/hello** (a forward slash followed by the word hello) into the property and save the Operations Editor popup.

   <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-3f04bce6e11334a32ff591ba6b1b61e6fe12b873%2Ffsro4.gif?alt=media" alt=""><figcaption></figcaption></figure>
9. In the **Solution Explorer**, locate the SimpleRESTHost service and its endpoint called **Operation1**. Click on Operation1 to **open it as a tab** in the center of the Designer.

   <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-8045c3c6421ca77a3d4d5be397fbfc8a1161220a%2Ffsro5.gif?alt=media" alt=""><figcaption></figcaption></figure>
10. In the plugins panel on the right of the Designer, locate an item called **String** (it has a green **STR** prefix) inside of the Linx plugin and **drag it into the tab called Operation1**.
11. In the properties panel in the bottom left of the Designer, locate the property called **Name** and change the value from **String** to **MyString**.
12. Locate another property of **MyString** called **Value** and enter **Hello World**.

    <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-5d09e4fa916bf446d4e76c53432112673c332a70%2Ffsro6.gif?alt=media" alt=""><figcaption></figcaption></figure>
13. In the plugins panel on the right of the Designer, locate a function called **Return** (it has a blue **FNC** prefix) inside of the Linx plugin and **drop it under MyString** in the tab Operation1.
14. Select the Return function and locate the property called **value** in the properties panel in the bottom left of the Designer.
15. Open the drop-down of the property and select the **Values Editor** to launch the Values Editor popup (or click the square edit icon in the property).
16. Find the **ResponseBody** property in the Values Editor popup, open the drop-down and select **MyString**. Then, save the editor.

    <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-25ed3dfbb5dc58eef5427b2fa6f7d14d98b0199a%2Ffsro7.gif?alt=media" alt=""><figcaption></figcaption></figure>
17. **Right-click on the SimpleRESTHost** in the Solution Explorer and select an item called [**Debug**](https://docs.linx.software/reference/designer/debugging) to place the Designer into Debug mode.
18. In the **Debug Output** panel at the bottom of the Designer, wait for a message that says **Ready to debug. Click START to start debugging**. When you see it, click the **Start** button in the top left of the Designer.
19. Now browse to this link: <http://localhost:8023/hello>, and you should see the string value (“Hello World”) in the browser. The /hello causes the SimpleRESTHost to fire the Operation1 event handler, which then runs the logic it contains and returns the ResponseBody.

    <figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-68c59b69e99300c72d0cd2e9ed8f5bd736c3e56b%2Ffsro8.gif?alt=media" alt=""><figcaption></figcaption></figure>

***

## How It Works

When you browse to the link (<http://localhost:8023/hello>), the SimpleRESTHost service fires the event for the path /hello called Operation1.\
Linx first instantiates the String and then assigns the String value to the ResponseBody property of Operation1.\
Operation1 then returns the ResponseBody together with a few other bits of information to the caller.

***

## Challenge

If you had fun building this solution in Linx, why not extend it a bit further? Instead of returning a static string:

* Change the String value to **Hello \[your name]** and debug the service again.
* Use the CallRESTService function from the REST plugin to call another REST service and assign the ResponseBody property to the ResponseBody property of Operation1.
* Use the TextFileRead function from the File plugin to read the contents of a text file and assign it to the ResponseBody property.
* Use the ExecuteSQL function from the Database plugin to connect to a database on your machine and select some data from a database table to display.

***

## Links

* Check out our [samples repo on Github](https://github.com/linx-software/samples) and find out what else you can build with Linx.
* [Comprehensive REST Guide](https://docs.linx.software/guides/rest).
* [Linx community posts about REST](https://community.linx.software/community/search?q=REST).
