This draft implementation helps to expose existing or new OFBiz services as REST. To facilitate this, added a new "verb" attribute to service elements that helps to determine how a particular service can be accessed via REST. Those changes are here : https://github.com/girishvasmatkar/ofbiz-framework/tree/feature/add-service-verb So, you need to be on
Repository : https://github.com/girishvasmatkar/ofbiz-framework.git
Branch : feature/add-service-verb
Another DEMO plug-in has a POST service (searchProductsByGoodIdentificationValue)(exprt="true" verb="post") defined -
https://github.com/girishvasmatkar/rest-demo.git
Once deployed, following URLs can be accessed
-
GET /rest/services
-
GET /rest/services/{serviceName}?inParams=<URLEncodedJSON>
-
POST /rest/services/{serviceName} (For this endpoint, the service in parameters must be part of Request Body)
Draft implementation inluced Bearer Auth Scheme. Authentication scheme is "Bearer <JWT>". The implementation can be update to include other authentication schemes as well. Example -
GET /rest/services HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBcGFjaGVPRkJpeiIsImlhdCI6MTU0NzczOTM0OCwiZXhwIjoxNjc5Mjc1MzQ4LCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiR2l2ZW5OYW1lIjoiSm9obm55IiwiU3VybmFtZSI6IlJvY2tldCIsIkVtYWlsIjoianJvY2tldEBleGFtcGxlLmNvbSIsInVzZXJMb2dpbklkIjoiYWRtaW4iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.fwafgrgpodBJcXxNTQdZknKeWKb3sDOsQrcR2vcRw97FznD6mkE79p10Tu7cqpUx7LiXuROUAnXEgqDice-BSg
-
List All Services (export="true" and verb = "get|post")
GET /rest/services HTTP/1.1 Content-Type: application/json Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBcGFjaGVPRkJpeiIsImlhdCI6MTU0NzczOTM0OCwiZXhwIjoxNjc5Mjc1MzQ4LCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiR2l2ZW5OYW1lIjoiSm9obm55IiwiU3VybmFtZSI6IlJvY2tldCIsIkVtYWlsIjoianJvY2tldEBleGFtcGxlLmNvbSIsInVzZXJMb2dpbklkIjoiYWRtaW4iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.fwafgrgpodBJcXxNTQdZknKeWKb3sDOsQrcR2vcRw97FznD6mkE79p10Tu7cqpUx7LiXuROUAnXEgqDice-BSg
Response :
{
"statusCode" : 200,
"statusDescription" : "OK",
"successMessage" : "OK",
"data" : [ {
"name" : "findProductById",
"description" : "Finds productId(s) corresponding to a product reference, productId or a GoodIdentification idValue",
"link" : {
"href" : "https://localhost:8443/rest/services/findProductById",
"rel" : "self",
"type" : "get"
}
}, {
"name" : "searchProductsByGoodIdentificationValue",
"description" : "Search Products by Good Identification Value",
"link" : {
"href" : "https://localhost:8443/rest/services/searchProductsByGoodIdentificationValue",
"rel" : "self",
"type" : "post"
}
} ]
}
-
Call OFBiz service via GET(export="true" and verb = "get|post")
GET /rest/services/findProductById?inParams=%7B%22idToFind%22:%22GZ-1001%22%7D HTTP/1.1 +
Content-Type: application/json +
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBcGFjaGVPRkJpeiIsImlhdCI6MTU0NzczOTM0OCwiZXhwIjoxNjc5Mjc1MzQ4LCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiR2l2ZW5OYW1lIjoiSm9obm55IiwiU3VybmFtZSI6IlJvY2tldCIsIkVtYWlsIjoianJvY2tldEBleGFtcGxlLmNvbSIsInVzZXJMb2dpbklkIjoiYWRtaW4iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.fwafgrgpodBJcXxNTQdZknKeWKb3sDOsQrcR2vcRw97FznD6mkE79p10Tu7cqpUx7LiXuROUAnXEgqDice-BSg
Response :
{
"statusCode" : 200,
"statusDescription" : "OK",
"data" : {
"product" : {
"createdStamp" : "2020-06-11T15:29:58.182+0000",
"productName" : "Nan Gizmo",
"createdByUserLogin" : "admin",
"productId" : "GZ-1001",
"taxable" : "Y",
"primaryProductCategoryId" : "101",
"createdTxStamp" : "2020-06-11T15:29:57.523+0000",
"lastUpdatedTxStamp" : "2020-06-11T15:29:57.523+0000",
"isVirtual" : "N",
"autoCreateKeywords" : "Y",
"description" : "Indian style Nan gizmo",
"chargeShipping" : "Y",
"internalName" : "Nan Gizmo",
"lastModifiedByUserLogin" : "admin",
"lastUpdatedStamp" : "2020-06-11T15:29:58.182+0000",
"lastModifiedDate" : "2001-05-13T06:30:00.000+0000",
"productTypeId" : "FINISHED_GOOD",
"createdDate" : "2001-05-13T06:30:00.000+0000",
"isVariant" : "N"
}
}
}
-
Call OFBiz Service via POST
POST rest/services/searchProductsByGoodIdentificationValue HTTP/1.1 Content-Type: application/json Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJBcGFjaGVPRkJpeiIsImlhdCI6MTU0NzczOTM0OCwiZXhwIjoxNjc5Mjc1MzQ4LCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiR2l2ZW5OYW1lIjoiSm9obm55IiwiU3VybmFtZSI6IlJvY2tldCIsIkVtYWlsIjoianJvY2tldEBleGFtcGxlLmNvbSIsInVzZXJMb2dpbklkIjoiYWRtaW4iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.fwafgrgpodBJcXxNTQdZknKeWKb3sDOsQrcR2vcRw97FznD6mkE79p10Tu7cqpUx7LiXuROUAnXEgqDice-BSg { "idFragment": "2644" }
Response
{
"statusCode" : 200,
"statusDescription" : "OK",
"data" : {
"products" : [ {
"internalName" : "Round Gizmo",
"productId" : "GZ-2644",
"primaryProductCategoryId" : "101",
"isVariant" : "N",
"goodIdentificationTypeId" : "INVOICE_EXPORT",
"idValue" : "GZ-2644-replaced",
"isVirtual" : "N"
} ]
}
}