# 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)](/reference/plugins/rest/content/simpleresthost.md) and [RESTHost (for advanced APIs)](/reference/plugins/rest/content/resthost.md).

***

## 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="/files/7JgTPvGqmnxp8FkxcRZm" 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="/files/4sbjPk4fjejDui06klBi" 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="/files/XJ34zdcgdKnTOfz3Ybox" 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="/files/byMCuhqLQMfT9mh7Sv4A" 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="/files/Q0ndsfiLmV28NK8zv1WY" 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="/files/kmID1bzdCKB6XRXyrigb" 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="/files/VoBfKIzDbtUuJGcfUIyt" alt=""><figcaption></figcaption></figure>
17. **Right-click on the SimpleRESTHost** in the Solution Explorer and select an item called [**Debug**](/reference/designer/debugging.md) 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="/files/CaQXAGWLJjfx8FfGfUva" 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](/guides/rest.md).
* [Linx community posts about REST](https://community.linx.software/community/search?q=REST).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.linx.software/first-applications/backend.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
