---
title: "rest:server — RESTful server"
description: "iXML command rest:server: RESTful server."
canonical_url: "https://www.zeyos.com/ixml/ref/rest-server"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ref/rest-server.md"
section: "ixml-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/ixmldoc.xml"
source_sha256: "a23f04e6a98628ca3c273c3b8dd2c33c034cfda3e0f00478d8793074fd2f70dd"
---

# rest:server — RESTful server

The REST:SERVER construct is a control flow structure that allows for selective execution of code according to the underlying RESTful request based on HTTP, in which each resource is a special type of subroutine.

REST:SERVER will invoke the resource subroutine of the first route that matches the current HTTP request's path and method with the associated request header field name and value pairs assigned to 'var_header' and the request body assigned to 'var_body'. Also, resource route arguments of the form ':name' as well as query arguments are assigned to corresponding local variables. The route may contain a final variadic argument of the form '*name' for all remaining route components as an array.

The USE construct declares a free function variable for use as a local variable within the resource subroutine that is explicitly bound to a corresponding variable from the immediate context within which the RESTful server is defined, thereby directly referencing the non-local variable from the parent scope outside of the inherent context of the resource subroutine.

### Attributes
- (none)

### Children
- rest:resource (occurrence: multiple) — RESTful resource definition

### Parents
- (not restricted in the reference)

### Result
- (none documented)

### Examples

```xml
<global var="people"/>

<array var="people">
	<array key="bg">
		<item key="lastname">Gates</item>
		<item key="firstname">Bill</item>
	</array>

	<array key="sj">
		<item key="lastname">Jobs</item>
		<item key="firstname">Steve</item>
	</array>
</array>

<rest:server>
	<rest:resource route="/person/:id" method="GET">
		<array:keyexists var="people" var_result="exists">$id</array:keyexists>

		<is var="exists" type="false">
			<set var="return">404</set>
			<return/>
		</is>

		<header>Content-Type: application/json</header>

		<output>
			<encode:json var="people[$id]"/>
		</output>
	</rest:resource>

	<rest:resource route="/person/:id" method="POST">
		<set var="people[$id].lastname">$lastname</set>
		<set var="people[$id].firstname">$firstname</set>
	</rest:resource>

	<rest:resource route="/person/:id" method="PUT" var_body="data">
		<decode:json var="people[$id]">$data</decode:json>
		<set var="return">201</set>
	</rest:resource>

	<rest:resource route="/person/:id" method="DELETE">
		<unset var="people[$id]"/>
	</rest:resource>
</rest:server>
```
