ThingWorx WebSocket-based Edge MicroServer (WS EMS) and Lua Script Resource (LSR) > REST Web Services Supported by WS EMS
  
REST Web Services Supported by WS EMS
The WS EMS is built to reflect the ThingWorx REST Web Service, but it is not a complete reflection. Rather, it is reflection of those Web Services that are most useful at the Edge. For example, if you try to look at Resources, nothing is returned. If you try to look at properties for a thing that either is running the WS EMS or that is registered with it (WS EMS is running as a gateway), you can see all the properties. By default, the WS EMS returns data in JSON format.
For example, these Web Services do work with a WS EMS:
/Thingworx/Things/thing_name/Properties
/Thingworx/Things/thing_name/Properties/prop_name
where thing_name represents the name of any device that is connected to the local WS EMS where you are using a REST Web Service, and prop_name represents the name of any property for the specified device.
* 
As of v.5.4.2, support for CSRF tokens has been added to the REST API for WS EMS and LSR. It is enabled by default. Before using the REST API, be sure to read CSRF Token Support.
Browser-based Use of REST Web Services
The REST Web Services of the ThingWorx platform can be used in a browser or an application that supports the HTTP commands. However, the behavior of the REST Web Services on a WS EMS is slightly different.
You cannot use a PUT through a query parameter of the REST Web Service in a browser, as on a ThingWorx platform. For example, the following use of PUT works on a platform, but not on a WS EMS:
https://<server_ip/Thingworx/Things/<thing_name>/Properties/<property_name>/
method=put&<prop_name>=<value>
You actually must do an HTTP PUT to the WS EMS, using a REST client that can do an HTTP PUT.
Another difference with the ThingWorx REST Web Services lies in how a WS EMS returns the information for a specific property. Both ThingWorx and a WS EMS use an infotable to return the information. However, a WS EMS returns the rows first and the data shape second. This order is the opposite from the order in which the ThingWorx REST Web Services return the information.
Similarly, for services, the following use of a service such as GetDescription works on a ThingWorx platform, but not on a WS EMS:
https://<server_ip>/Thingworx/Things/thing_name/Services/GetDescription
For WS EMS, you must request to run services by using a POST through a client that can do an HTTP POST.
* 
You cannot send POST commands using a web browser if CSRF tokens are enabled (enabled by default and strongly recommended to keep enabled). You must use POSTMAN or another REST client.
As long as you do not have any input parameters for the service and if CSRF tokens are not enabled (strongly discouraged), you could do it this way from a browser:
https://localhost:8000/Thingworx/Things/thing_name/Services/
GetDescription/method=POST
However, if you have parameters and leave CSRF tokens enabled, use a client that can do an HTTP POST.
Here are a few of the REST Web Services of the ThingWorx that do not work with WS EMS:
/Thingworx/Things
/Thingworx/Things/thing_name
/Thingworx/Resources
By default, a WS EMS uses application/json for the Accept header.
* 
As of v.5.4.2, support for CSRF tokens has been added to the REST API for WS EMS and LSR. It is enabled by default. Before using the REST API, be sure to read CSRF Token Support in REST API for WS EMS and LSR.
Using a REST Client with a WS EMS
You can use a REST client such as Postman to run REST Web Services against a WS EMS. You can save them and even set up collections of them. In addition, you can export a collection and import them into a Javascript engine such as Node.js.
* 
Before using Postman, be sure to read Running REST API Calls with Postman on WS EMS and LSR and in particular, the section, CSRF Token Support in REST API for WS EMS and LSR.
When you are using REST Web Services, it is important to set your headers correctly:
Accept — Specifies the format in which the data should be returned — JSON for WS EMS. For ThingWorx platform, you can also choose XML or text.
Application Key (appKey) — Provides the authentication you need with the platform. You do not need it when running a REST Web Service against a local WS EMS.
Although the Application Key is strongly recommended when running a REST Web Service against a remote WS EMS, you can use basic authentication. In Postman, you can select Basic Authorization and specify a user name and password to access the ThingWorx platform.
x-thingworx-session — Determines if your request will set up an HTTP session with the ThingWorx instance. Having a session makes it possible to send multiple requests from a browser to ThingWorx Composer without having to authenticate with each request. When you set up a session, the browser and Composer authenticate each request in the background.
However, in an application, you do not want a session because sessions take up memory. For an application, set this header to false so that the ThingWorx platform does not create a session every time that the application sends a request. Sending the appKey with each request does not impact memory.
* 
If you use Basic authentication, you always get a session with the ThingWorx platform. With an application, use an appKey for authentication and set the x-thingworx-session header to false.
x-csrf-token — A random string used for Cross-Site Request Forgery (CSRF) protection in the WS EMS. When authentication and CSRF tokens are enabled on the WS EMS, the WS EMS will return a random CSRF token with each response that must be used in the next client request. If this token is not included or is incorrect, the request will fail with a 401 Unauthorized error.
Using Services with a WS EMS
The following services work as REST Web Services with both a ThingWorx platform and a WS EMS:
AddEdgeThing
GetConfiguration
GetEdgeThings
GetLogData
GetMicroserverVersion
HasEdgeThing
RemoveEdgeThing
ReplaceConfiguration
Restart
StartFileLogging
StopFileLogging
TestPort
UpdateConfiguration
The WS EMS also supports using the isConnected property with a REST Web Service.
* 
As of v.5.4.2, support for CSRF tokens has been added to the REST API for WS EMS and LSR. It is enabled by default. Before using the REST API, be sure to read CSRF Token Support in REST API for WS EMS and LSR.