////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////
[[WebService-WebService]]
:imagesdir: ../assets/images/hop-server/
:description: Hop has a simple way of exposing data through a servlet.

= Web Service

== Introduction

Hop has a simple way of exposing data through a servlet.

For more information on configuring the Hop server check the xref:hop-server/index.adoc[Hop Server docs] +

== Web Service Metadata

=== Screenshot

image::hop-server/web-service-example.png[Web Service metadata example,75%,align="left"]

=== Options

|===
|Option |Description

|Name
|The name of the web service.
This is the name that is passed into the webService URL.

|Enabled
|Enables or disabled the web service

|Filename on the server
|This is the filename on the server.
Make sure that the pipeline you want to execute is available on the server.

|Output transform
|The name of the transform from which this service will take the output row(s).

|Output field
|The output field from which this service will take data from, convert it to a String and output it

|Content type
|The content type which will get reported by the webService servlet

|List status on server
|Enable this option if you want the executions of the web service pipeline to be listed in the status of the server.

|Request body content variable
|This is the name of the variable which at runtime will contain the content of the request body content.  This is useful when doing a POST against the webservice.

|===

== Hop Server configuration

Your Hop Server needs to know about the metadata you defined.
As stated above you need to make sure the server has access to the pipeline(s) you want to execute as well as the server metadata.

The best way to do this is to set the following option in your XML configuration file:

Linux
[source,xml]
----
<metadata_folder>/path/to/your/metadata</metadata_folder>
----

Windows
[source,xml]
----
<metadata_folder>C:\\path\\to\\your\\metadata</metadata_folder>
----

A simple example would be:

[source,xml]
----
<hop-server-config>
  <hop-server>
    <name>8181</name>
    <hostname>localhost</hostname>
    <port>8181</port>
  </hop-server>
  <metadata_folder>/home/hop/project/services/metadata</metadata_folder>

</hop-server-config>
----

== Using the service

=== Base request (ATTENTION: Use the S word capitalized)

[source,http request]
----
http://<hop-server-url>/hop/webService
----

=== Request parameters

|===
|Parameter |Description

|`service`
|The name of the service.
This corresponds to the Web Service metadata object.

|`runConfig`
|The name of the pipeline run configuration.
Please note that returning values is only supported on the "Local" pipeline engine.

|Any parameter name
|Any parameter can be set simply by passing the value through the request URL

|Any variable name
|Any variable can be set simply by passing the value through the request URL

|===

=== POST

Beside the default GET you can also do a POST against the web service and pass in a request body.  The content of this body is then picked up if you set the request body content variable.  This variable will contain the body content every time the POST request triggers the execution of the underlying pipeline.

=== Request example

The following executes Hop Web Service `test` as seen in the screenshot above.
It passes a parameter B and a variable A and outputs JSON produced by a JSON Output transform.

[source,http request]
----
http://localhost:8181/hop/webService/?service=test&A=valueA&B=valueB
----

The web service pipeline looks like this:

image::hop-server/web-service-pipeline-example.png[Web Service pipeline example,75%,align="left"]

