Using our resources for the Products API
#
IntroductionIn this integration we will complete our ProductsAPI integration we have been working on from the past couple of lessons. Using the API Ingress we created and the Jetlet we created in the last lesson we are going to see how we can use these to query, create, and even delete records from our database.
#
VisiosnCorp’s requestVisionsCorp (VC) needs the ability to perform various common Database operations using the Jetic Platform. Luckily Jetic has many capabilities to do just that. Working on the integration you started in the previous lessons you will have the ability to perform all that VisionsCorp needs to enable the company to continue their business necessities.
- GET, POST, DELETE methods
- SQL (created in the last lesson)
- SET BODY
- Unmarshal
- Log
- TO JSON (Marshal → JSON)
#
Goals:- Build a more complex integration
- Use a Jetlet
- Marshal into JSON
- Add, delete, and retrieve products from a database
#
Step 1: Create the 1st route- Return back to the integration, namely ProductsAPI
- In the first swing lane drag the GetProducts (plural) into the lane
- Check and make sure the endpoint is / and the operation is GetProducts
- Under the Get Method, add the Jetlet that we created, namely JsonSQL
- In the JsonSQL component, add the SELECT * FROM PRODUCT as the query
note
Keep in mind that the DB resource needs to have a table named PRODUCT with data in it. Adding a table with the proper data is beyond the scope of this lesson.
#
Step 2: Create the 2nd route- In the second swing lane drag the GetProduct (singular) into the lane
- Check and make sure the endpoint is /products/{id} and the operation is GetProduct
- Under the Get Method, add the Jetlet that we created, namely JsonSQL
- In the JsonSQL component, add the SELECT * FROM PRODUCT WHERE id=:#${header.id} as the query
#
Step 3: Create the 3rd route- In the third swing lane drag the CreateProduct into the lane
- Under the POST Method, add the Jetlet that we created, namely ReadJson
- Under that Jetlet add a SQL component
- Add this Query
INSERT INTO jetic_logistics_demo
.product
(
sku
,
name
,
reserved_stock
,
stock
,
price
)
VALUES
(
:#${body[sku]},
:#${body[name]},
:#${body[reserved_stock]},
:#${body[stock]},
:#${body[price]}
);
- For the data source bean add #logistics
- Under that SQL component add another SQL component
- Add this Query to the second consecutive SQL component SELECT * FROM
jetic_logistics_demo
.product
WHEREid
= last_insert_id(); - Finally, add a To JSON component
#
Step 4: Create the 4th route:- In the fourth swing lane drag the DeleteProduct into the lane
- Check and make sure the endpoint is /products/{id} and the operation is DeleteProduct
- Under the Delete Method, add a SQL component
- In the SQL component, for the Query, add DELETE FROM PRODUCT WHERE id = 4; (Or any other arbitrary number you would like to test)
🎉 Congratulations you have created an API that allows your Jetic user to make and mutate data using Jetic. You have created REST APIs to use and also created your very first Jetlets. 🎉