<commit_before>---
layout: post101
title:  REST API
categories: XAP101
parent: rest-service-overview.html
weight: 400
---


{%wbr%}

{%section%}
{%column width=10% %}
![data-access.jpg](/attachment_files/web-services.jpg)
{%endcolumn%}
{%column width=90% %}
XAP REST interface.
{%endcolumn%}
{%endsection%}

<hr/>

The REST API exposing HTTP based interface Space. It is leveraging the [GigaSpace API](./the-gigaspace-interface.html). It support the following methods:

1. GET - can be used to perform an introduceType, readByID or a readMultiple action by a space query.
1. POST - can be used to perform a write / writeMultiple or update / updateMultiple actions.
1. DELETE - can be used to perform take / takeMultiple actions either by ID or by a space query.

<br/>

## Actions


{% togglecloak id=1 %}- Introduce Type{% endtogglecloak %}
{% gcloak 1 %}
{% panel title=Description| borderStyle=solid|borderColor=#3c78b5 %}
Introduce the specific type to space by registering it and setting the SpaceId and RoutingId to `id` unless a query parameter "id" is provided.
{%endpanel%}

{% panel title=Request Schema| borderStyle=solid|borderColor=#3c78b5 %}
####Request URL
{% highlight bash %}
GET http://localhost:8080/{Type}/_introduce_type
{% endhighlight %}

####Request Query Parameters
spaceid - The [SpaceId](./space-object-id-operations.html) attribute of the type
{%endpanel%}

{% panel title=Response Schema| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight json %}
{
   "status":"success"
}
{% endhighlight %}
{%endpanel%}

{% panel title=Examples| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight bash %}
http://localhost:8080/MyObject/_introduce_type
http://localhost:8080/MyObject/_introduce_type?spaceid=id
{% endhighlight %}
{%endpanel%}
{% endgcloak %}

{% togglecloak id=21 %}- Single Write{% endtogglecloak %}
{% gcloak 21 %}
{% panel title=Description| borderStyle=solid|borderColor=#3c78b5 %}
Write single entry to the space.
{%endpanel%}

{% panel title=Request Schema| borderStyle=solid|borderColor=#3c78b5 %}
####Request URL
{% highlight bash %}
POST http://localhost:8080/{Type}/
{% endhighlight %}

####Request Headers
Content-Type: application/json

####Request Body
JSON object representation of a SpaceDocument object.
{%endpanel%}


{% panel title=Response Schema| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight json %}
{
   "status":"success"
}
{% endhighlight %}
{%endpanel%}

{% panel title=Examples| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight bash %}
curl -XPOST -H "Content-Type: application/json" -d '{"id":"1", "data":"testdata", "data2":"common", "nestedData" : {"nestedKey1":"nestedValue1"}}' http://localhost:8080/MyObject
{% endhighlight %}
{%endpanel%}
{% endgcloak %}

{% togglecloak id=2 %}- Write Multiple{% endtogglecloak %}
{% gcloak 2 %}
{% panel title=Description| borderStyle=solid|borderColor=#3c78b5 %}
Write multiple entries to the space.
{%endpanel%}

{% panel title=Request Schema| borderStyle=solid|borderColor=#3c78b5 %}
####Request URL
{% highlight bash %}
POST http://localhost:8080/{Type}/
{% endhighlight %}

####Request Headers
Content-Type: application/json

####Request Body
JSON array representation of a SpaceDocument objects.
{%endpanel%}


{% panel title=Response Schema| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight json %}
{
   "status":"success"
}
{% endhighlight %}
{%endpanel%}

{% panel title=Examples| borderStyle=solid|borderColor=#3c78b5 %}<commit_msg>modified REST config<commit_after>---
layout: post101
title:  REST API
categories: XAP101
parent: rest-service-overview.html
weight: 400
---




{%section%}
{%column width=10% %}
![data-access.jpg](/attachment_files/web-services.jpg)
{%endcolumn%}
{%column width=90% %}
{% summary  %}{% endsummary %}
{%endcolumn%}
{%endsection%}


The REST API exposing HTTP based interface Space. It is leveraging the [XAP API](./the-gigaspace-interface.html). It support the following methods:

1. GET - can be used to perform an introduceType, readByID or a readMultiple action by a space query.
1. POST - can be used to perform a write / writeMultiple or update / updateMultiple actions.
1. DELETE - can be used to perform take / takeMultiple actions either by ID or by a space query.

<br/>


# Introduce Type

{: .table .table-bordered .table-condensed}
|Description |Introduce the specific type to space by registering it and setting the SpaceId and RoutingId to `id` unless a query parameter "id" is provided.|
|Request URL| GET http://localhost:8080/{Type}/_introduce_type  |
|<nobr>Request Query Parameters</nobr>|spaceid - The [SpaceId](./space-object-id-operations.html) attribute of the type |

Response Schema:
{% highlight json %}
{
   "status":"success"
}
{% endhighlight %}

Examples:
{% highlight bash %}
http://localhost:8080/MyObject/_introduce_type
http://localhost:8080/MyObject/_introduce_type?spaceid=id
{% endhighlight %}


{%comment%}
{% togglecloak id=1 %}- Introduce Type{% endtogglecloak %}
{% gcloak 1 %}
{% panel title=Description| borderStyle=solid|borderColor=#3c78b5 %}
Introduce the specific type to space by registering it and setting the SpaceId and RoutingId to `id` unless a query parameter "id" is provided.
{%endpanel%}

{% panel title=Request Schema| borderStyle=solid|borderColor=#3c78b5 %}
####Request URL
{% highlight bash %}
GET http://localhost:8080/{Type}/_introduce_type
{% endhighlight %}

####Request Query Parameters
spaceid - The [SpaceId](./space-object-id-operations.html) attribute of the type
{%endpanel%}

{% panel title=Response Schema| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight json %}
{
   "status":"success"
}
{% endhighlight %}
{%endpanel%}

{% panel title=Examples| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight bash %}
http://localhost:8080/MyObject/_introduce_type
http://localhost:8080/MyObject/_introduce_type?spaceid=id
{% endhighlight %}
{%endpanel%}
{% endgcloak %}

{%endcomment%}

# Single Write

{: .table .table-bordered .table-condensed}
|Description | Write single entry to the space.|
|Request URL | POST http://localhost:8080/{Type}/ |
|Request Headers|Content-Type: application/json   |
|Request Body | JSON object representation of a SpaceDocument object.|

Response Schema:
{% highlight json %}
{
   "status":"success"
}
{%endhighlight%}

Examples:
{% highlight bash %}
curl -XPOST -H "Content-Type: application/json" -d '{"id":"1", "data":"testdata", "data2":"common", "nestedData" : {"nestedKey1":"nestedValue1"}}' http://localhost:8080/MyObject
{% endhighlight %}


{%comment%}
{% togglecloak id=21 %}- Single Write{% endtogglecloak %}
{% gcloak 21 %}
{% panel title=Description| borderStyle=solid|borderColor=#3c78b5 %}
Write single entry to the space.
{%endpanel%}

{% panel title=Request Schema| borderStyle=solid|borderColor=#3c78b5 %}
####Request URL
{% highlight bash %}
POST http://localhost:8080/{Type}/
{% endhighlight %}

####Request Headers
Content-Type: application/json

####Request Body
JSON object representation of a SpaceDocument object.
{%endpanel%}

{% panel title=Response Schema| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight json %}
{
   "status":"success"
}
{% endhighlight %}
{%endpanel%}

{% panel title=Examples| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight bash %}
curl -XPOST -H "Content-Type: application/json" -d '{"id":"1", "data":"testdata", "data2":"common", "nestedData" : {"nestedKey1":"nestedValue1"}}' http://localhost:8080/MyObject
{% endhighlight %}
{%endpanel%}
{% endgcloak %}

{%endcomment%}

{% togglecloak id=2 %}- Write Multiple{% endtogglecloak %}
{% gcloak 2 %}
{% panel title=Description| borderStyle=solid|borderColor=#3c78b5 %}
Write multiple entries to the space.
{%endpanel%}

{% panel title=Request Schema| borderStyle=solid|borderColor=#3c78b5 %}
####Request URL
{% highlight bash %}
POST http://localhost:8080/{Type}/
{% endhighlight %}

####Request Headers
Content-Type: application/json

####Request Body
JSON array representation of a SpaceDocument objects.
{%endpanel%}


{% panel title=Response Schema| borderStyle=solid|borderColor=#3c78b5 %}
{% highlight json %}
{
   "status":"success"
}
{% endhighlight %}
{%endpanel%}

{% panel title=Examples| borderStyle=solid|borderColor=#3c78b5 %}
{'fraction_non_alphanumeric': 0.15474452554744525, 'fraction_numerical': 0.027250608272506083, 'mean_word_length': 5.6783103168155975, 'pattern_counts': {'":': 20, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5607825', 'n_tokens_mistral': 2955, 'n_tokens_neox': 2502, 'n_words': 703}