Git Product home page Git Product logo

ofbiz-rest-impl's Introduction

Apache OFBiz® plugin for REST

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

Endpoints

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)

Authentication

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

Example

  • 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"
    } ]
  }
}

ofbiz-rest-impl's People

Contributors

girishvasmatkar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.