The phrases rapid prototyping and SAP Hybris Commerce usually don't go together. SAP Hybris Commerce is an amazing digital commerce platform, but it doesn't lend itself to rapid development. With this tutorial, I will demonstrate how to dramatically speed up your REST API development time, and provide an alternative approach to rapid development using SAP Hybris Commerce. During my own API development cycles, the com.sun.net.httpserver has shortened my build and server start-up times to less than five seconds!
As you may or may not know, the Java Development Kit (JDK ) is bundled with an embedded Web server. The com.sun.net.httpserver package was introduced with JDK 1.6, and enables embedded HTTP servers quite nicely. This tutorial was tested with both Oracle JDK 1.7.x/1.8.x, as well as, OpenJDK 6/7 on Windows and Ubuntu operating systems.
Let's get started!
Step by Step Instructions
1. Goto Hybris Administrative Console (HAC) in your Web browser. (If Hybris is running on your local machine, goto https://localhost:9002/ in your Web browser)
2. Enter your admin user name and password at HAC login screen. (The following screenshot displays the HAC login page with username and password entered)
3. Upon logging in successfully, goto Console -> Scripting Languages
4. Please email email@example.com to receive the code for the Embedded REST API Server for SAP Hybris Commerce
5. Once you have the code, please Copy and paste the contents of the Groovy script into the Scripting Languages Console:
Your console should resemble the following:
6. Click on the Execute button to start the Embedded REST API Server.
7. Go to your command console window or console.log file to confirm the server has been started properly. Below is confirmation that the Embedded REST API Server has been started properly.
Notice that the REST API Server started in one second!
8. In a separate browser tab or window, enter the following: http://localhost:8900/test and press the Enter key.
If your Embedded REST API Server is successfully running, you will should see the following REST Response.
9. The Embedded REST API Server is also equipped with its own product API. For example, if you still have the OOTB electronics product catalog in your development environment copy and paste the following URL into a separate browser tab or window:
You should see the following output, if the electronicsProductCatalog is still in your Hybris Commerce environment:
If you don't have the electronicsProductCatalog in your Hybris environment, no problem.
The URL path in blue bold letters are configurable, and you may replace them with values that match your current Hybris environment:
May be changed to:
10. To Shutdown the Embedded REST API Server, copy and paste the following URL into your browser: http://localhost:8900/shutdown and press the Enter key
11. The Embedded REST API Server tutorial is complete.
In upcoming articles, we will dive deeper in this tutorial's respective areas. Stay tuned!