<img src="https://secure.leadforensics.com/84962.png" style="display:none;">

Libraries

For some of the most common software platforms, libraries are available in order to streamline the implementation process. Use the buttons above to toggle this guide to show platform-specific information and code samples. The libraries are open source and available at our company page at GitHub.

SHOW INSTRUCTIONS FOR: Javascript PHP JSON JAVA .NET

Installation

You can find the latest version of the JavaScript Demo and Library on GitHub. The JS lib contains barebones functions for communication with the Loop54 SaaS API. The Demo uses this library to implement some common functionality, such as search and autocomplete. If choosing a client side implementation we recommend using this as a starting point to understand and/or get a flying start. 

Demo basics

The demo is a reference implementation of some of the possible features using a Loop54 SaaS API. It is written in ES6 and uses promises. Build scripts for development and transpiling to ES5 using Node.js are included. 

The easiest way to get started is to check out the code from the GitHub repository and follow the instructions in the readme. The demo comes with a Hello World-example which connects to a Loop54 SaaS API containing a fruits store example. Exchange the config parameters given to you at signup to directly start using the demo with your company products and categories. 

The Demo keeps track of users (via cookies) and uses jQuery 2.1.1 and jQuery UI for autocomplete.

 

Installation

You can find the latest version of the PHP library at GitHub. Simply include the files in the dist directory in any scripts that need to use the library.

Library basics

The library has built-in serialization and HTTP handling, which means that your code only has to set up the method calls and take care of the response. It also has built-in methods for keeping track of users (via cookies). Note that in order for cookies to work properly, the library assumes that you make all your Loop54 requests before HTTP headers are sent to the client.

All methods are called by creating a request object, setting parameters(UTF-8 valid) on the request object, and then using that request object to generate a response.

The objects returned by the API are automatically translated to PHP classes. Some of the Loop54-specific classes used in the library are Loop54_Request, Loop54_Response, Loop54_Entity and Loop54_Event.

 

Code examples

//initialize request object and set parameters
$request = new Loop54_Request("requestname");
$request->setValue("StringParameter","string value");
$request->setValue("FloatParameter",5);
$request->setValue("ArrayParameter",array("array value 1", "array value 2"));

//get response object
$response = Loop54_RequestHandling::getResponse("http://helloworld.54proxy.com",$request);

//single values
$boolValue = $response->getValue("BoolResponseParameter");
$stringValue = $response->getValue("StringResponseParameter");

//collections
$coll = $response->getCollection("EntityCollectionParameter");
$entity = $coll[0]->key;

Installation

If you are serializing/deserializing JSON yourself instead of using a library, you don't need to download anything. Just make sure you serialize your data in the formats specified in the examples. Request names and parameter names are not case-sensitive, so you can use any casing standards.

Library basics

If you're not using a library, you will need to handle User tracking yourself. This means that, when a visitor first arrives to the site, assign a unique (random generated or GUID) ID to the user. This value should then be sent in a "UserId" parameter in every request to the engine.

Store the value in a cookie or other storage mechanism so that the ID remains through the user session, and also persists for the next time the same user visits. If you are using cookies, we recommend that you set a very long expiry date (3 years or so), so that it is possible to gather long-term information for personalization features.

We also recommend that the visitors IP address is sent to the engine, so that we can remove bots and internal traffic from statistics, engine learning and usage level calculations.

 

Code examples

POST to http://helloworld.54proxy.com/requestname
{
    "StringParameter" : "parameter value",
    "FloatParameter" : 0.5,
    "ArrayParameter" : ["array value 1", "array value 2"],

    "UserId" : "helloworlduser",
    "IP" : "0.0.0.0"
}

Response: 200 OK
{
    "Success" : true,
    "HeroId" : "The Glad Twin of the Grass",
    "Data" : {
        "BoolResponseParameter" : true,
        "StringResponseParameter" : "some string value",
        "EntityCollectionParameter" : [{
                "Key" : {
                    "EntityType" : "Product",
                    "ExternalId" : "123456",
                    "Attributes" : {
                        "Title" : "The product title",
                        "ImageUrl" : "http://yoursite.com/images/123456.png",
                        "Description" : "One of the best products ever. Period."
                    }
                },
                "Value" : 0.33
            }
        ]

    }
}

Installation

You can find the latest version of the Java library on GitHub. Reference the .jar-files (in the dist directory) in your project and you should be good to go!

Library basics

The library has built-in serialization and HTTP handling, which means that your code only has to set up the method calls and take care of the response. It also has built-in methods for keeping track of users (via cookies) and fallback strategies in case the main search engine should become unavailable.

All methods are called by creating a request object, setting parameters on the request object, and then using that request object to generate a response.

The objects returned by the API are automatically translated to Java classes. Some of the Loop54-specific classes used in the library are Request, Response, Entity, Event and Item, all available in the com.loop54.java package.

 

Code examples

//initialize request object and set parameters
Request loopRequest = new Request("requestname",request,response); //HttpServletRequest and HttpServletResponse
loopRequest.setValue("StringParameter","parameter value");
loopRequest.setValue("FloatParameter",0.5);

List anArray = new ArrayList();
anArray.add("array value 1");
anArray.add("array value 2");
loopRequest.setValue("ArrayParameter",anArray);

//get response object
Response loopResponse = RequestHandling.getResponse("http://helloworld.54proxy.com", loopRequest);

//single values
Boolean boolValue = loopResponse.getBoolean("BoolResponseParameter");
String stringValue = loopResponse.getString("StringResponseParameter");

//collections
List<Item> entityCollection = loopResponse.getItemArray("EntityCollectionParameter");
Entity entity = (Entity)entityCollection.get(0).key;

Installation

The latest release of the .NET library is available for download on NuGet and the source code is available on GitHub

Library basics

The library has built-in serialization and HTTP handling, which means that your code only has to set up the method calls and take care of the response. It also has built-in methods for keeping track of users (via cookies) and fallback strategies in case the main search engine should become unavailable.

All methods are called by creating a request object, setting parameters on the request object, and then using that request object to generate a response.

The objects returned by the API are automatically translated to .NET classes. Some of the Loop54-specific classes used in the library are Loop54.Request, Loop54.Response, Loop54.Public.Entity, Loop54.Public.Event and Loop54.Public.Item.

 

Code examples

//initialize request object and set parameters
var request = new Loop54.Request("RequestName");
request.SetValue("StringParameter", "parameter value");
request.SetValue("FloatParameter", 0.5f);
request.SetValue("ArrayParameter", new[] { "array value 1", "array value 2" });

//get response object
var response = Loop54.RequestHandling.GetResponse("http://helloworld.54proxy.com", request);

//single values
var boolValue = response.GetValue("BoolResponseParameter");
var stringValue = response.GetValue("StringResponseParameter");

//collections
var entityCollection = response.GetValue<list<item>>("EntityCollectionParameter");