Sunteți pe pagina 1din 22

REST API

The acronym REST stands for Representational State Transfer, this basically means that each unique
URL is a representation of some object. REST describes a set of architectural principles by which data
can be transmitted over a standardized interface (such as HTTP)

In a RESTful Web service, requests made to a resource's URI will elicit a response that may be
in XML, HTML, JSON or some other defined format. The response may confirm that some alteration
has been made to the stored resource, and it may provide hypertext links to other related resources or
collections of resources.

HTTP Methods
The following HTTP methods are most commonly used in a REST based architecture.

 GET − Provides a read only access to a resource.


 PUT − Used to create a new resource.
 DELETE − Used to remove a resource.
 POST − Used to update an existing resource or create a new resource.
 OPTIONS − Used to get the supported operations on a resource.

SR.No. HTTP Operation Operation Type


Method

1 GET Requests data from a specified resource Read Only

2 PUT Uploads a representation of the Idempotent


specified URI

3 POST Submits data to be processed to a N/A


specified resource

4 DELETE Delete the record or data Idempotent

List the supported operations in web


5 OPTIONS Read Only
service
HTTP Code
Always use standard HTTP codes while returning HTTP response to the client. Following are the status
codes.

Sr.No. HTTP Code & Description

200
1
OK − Shows success.

201

2 CREATED − When a resource is successfully created using POST or PUT request. Returns
link to the newly created resource using the location header.

204
3
NO CONTENT − When response body is empty. For example, a DELETE request.

304

4 NOT MODIFIED − Used to reduce network bandwidth usage in case of conditional GET
requests. Response body should be empty. Headers should have date, location, etc.

400

5 BAD REQUEST − States that an invalid input is provided. For example, validation error,
missing data.

401
6
UNAUTHORIZED − States that user is using invalid or wrong authentication token.

403
7
FORBIDDEN − States that the user is not having access to the method being used. For
example, Delete access without admin rights.

404
8
NOT FOUND − States that the method is not available.

409

9 CONFLICT − States conflict situation while executing the method. For example, adding
duplicate entry.

500

10 INTERNAL SERVER ERROR − States that the server has thrown some exception while
executing the method.
REST Web Services are available in Oracle E-Business Suite Release 12.2.3 and onwards only. REST
based web services are deployed on Oracle E-Business Suite’s application server. They do not dependent
on Oracle SOA Suite and Oracle Applications Adapter.

Integrated SOA Gateway


Oracle E-Business Suite Integrated SOA Gateway (ISG) is a complete set of service infrastructure to
provide, consume, and administer Oracle E-Business Suite Web services. You can use this tool to easily
discover and search on interfaces, regardless of custom or Oracle seeded ones.

Major Features of ISG


Oracle E-Business Suite Integrated SOA Gateway can do the following:

 Display all Oracle E-Business Suite integration interface definitions through Oracle Integration
Repository.
 Support custom integration interfaces from Oracle Integration Repository
 Provide service enablement capability (SOAP and REST services) for seeded and custom
integration interfaces within Oracle E-Business Suite
 Use the Integration Repository user interface to perform design-time activities such as generate
and deploy Oracle E-Business Suite Web services
 Support synchronous interaction pattern for REST-based Web services
 Support multiple authentication types for inbound service requests in securing Web service
content
 Enforce function security and role-based access control security to allow only authorized users to
execute administrative functions
 Provide centralized, user-friendly logging configuration for Web services generated through
Oracle E-Business Suite Integrated SOA Gateway's service provider
 Audit and monitor Oracle E-Business Suite inbound service operations from Service Monitor
 Leverage Oracle Workflow Business Event System to enable Web service invocation from Oracle
E-Business Suite
Exposing Standard API as REST Web Service and Invoking it.

Perform following steps to expose Pl/SQL as a web service

1). Search API in Integration Repository


2). Deploy API as REST Service
3). Create Grants for REST Service
4). Invoke EBS REST Service (in JSON message format)
5). Verify the results

Case - I : Creation Of Employee using REST API

Here we will take an example of creating an Employee by exposing HR_EMPLOYEE_API Interface API
and then invoking it to create Employee.

Following steps will explain the process of exposing the standard API and then invoking it.

Step 1: Navigate to Integration Repository Responsibility, Click on Search.


Then on search Page enter “HR_EMPLOYEE_API” in Internal Name and click on Go.

Step 2: Click on the search result, it will display List of methods available in the Interface
Package.

Click on REST Web Service Tab


We need to Deploy REST Web Service before it can be used as API to perform different
operations.

Step 3: Enter the value “Employee” in the field Service Alias (Mandatory). Check “Create
Employee” under Service Operations.

Step 4: Now click on the Deploy to make the REST web service active and usable. You will
receive message that service is successfully deployed and the status will be deployed
Step 5: Now you will see the link to WADL file, Click on the link. It shows the
physical location of the service endpoint where the service is hosted.

Now open the link highlighted in RED in new Browser window, it will show the XSD file with
input parameters that will be used later for invoking the Web Service.

Attaching JSON file for the aforesaid XSD

Step 6: In case you want to assign Grants to a group of user. You can do so and only those
people in the group can access and perform operation via REST APIs.

Click on the Grant, then Create Grants to provide the grants.


Step 7: Now we will invoke this web service using Advanced REST Client apps available in
Google Chrome.
Step 8: Enter the following header details:

Authorization by clicking on Add new header link then enters the application
username/password by clicking on construct.

Then enter Accept, Content Type and Language. Select application/json in the Content
Type and Accept below.

On performing the GET operation, I am getting HTTP response code – 200 OK


Step 9: Enter the following Link and payload information and click on send. The payload is
created using the xsd file generated at Step 5.

Link: http://hansel.rapidflowapps.com:8002/webservices/rest/Employee/create_employee/

Payload:
{
"CREATE_EMPLOYEE_Input": {
"@xmlns": "http://xmlns.oracle.com/apps/per/rest/Employee/create_employee/",
"RESTHeader": {
"xmlns": "http://xmlns.oracle.com/apps/per/rest/Employee/header",
"Responsibility":"US_HRMS_MANAGER",
"RespApplication":"PER",
"SecurityGroup":"STANDARD",
"NLSLanguage":"AMERICAN",
"Org_Id" :"204"
},
"InputParameters": {
"P_HIRE_DATE": "2015-06-28T09:00:00",
"P_BUSINESS_GROUP_ID":"202",
"P_LAST_NAME":"Negi",
"P_SEX":"M",
"P_PER_COMMENTS":"Create From REST Service",
"P_DATE_OF_BIRTH":"1979-01-04T09:00:00",
"P_EMAIL_ADDRESS":"psnegi@rapidflowapps.com",
"P_FIRST_NAME":"Praveen",
"P_KNOWN_AS":"Praveen",
"P_MARITAL_STATUS":"S",
"P_MIDDLE_NAMES":"Singh",
"P_NATIONALITY":"AM",
"P_NATIONAL_IDENTIFIER":"183-25-2523",
"P_REGISTERED_DISABLED_FLAG":"N",
"P_COUNTRY_OF_BIRTH":"US",
"P_REGION_OF_BIRTH":"West",
"P_TOWN_OF_BIRTH":"San Francisco"
}
}
}
Step 10: Now to verify if an Employee is created in Oracle. Query the table
PER_ALL_PEOPLE_F to check the result.
Case - II : Creation Of User using REST API

Here we will take an example of creating a User by exposing FND_USER_PKG Interface API and then
invoking it to create user.

Following steps will explain the process of exposing the standard API and then invoking it.

Step 1: Navigate to Integration Repository Responsibility, Click on Search.

Then on search Page enter “FND_USER_PKG” in Internal Name and click on Go


Step 2: Click on the search result, it will display List of methods available in the Interface
Package.

Click on REST Web Service Tab


We need to Deploy REST Web Service before it can be used as API to perform different
operations.

Step 3: Enter the value “create_user_test” in the field Service Alias (Mandatory). Check
“Create/Update User” under Service Operations.

Step 4: Now click on the Deploy to make the REST web service active and usable. You will
receive message that service is successfully deployed and the status will be deployed
Step 5: Now you will see the link to WADL file, Click on the link. It shows the
physical location of the service endpoint where the service is hosted.

Now open the link highlighted in RED in new Browser window, it will show the XSD file with
input parameters that will be used later for invoking the Web Service.

Attaching JSON file for the aforesaid XSD

Step 6: In case you want to assign Grants to a group of user. You can do so and only those
people in the group can access and perform operation via REST APIs.

Click on the Grant, then Create Grants to provide the grants.


Step 7: Now we will invoke this web service using Advanced REST Client apps available in
Google Chrome.

Step 8: Enter the following header details:

Authorization by clicking on Add new header link then enters the application
username/password by clicking on construct.

Then enter Accept, Content Type and Language. Select application/json in the Content
Type and Accept below.

On performing the GET operation, I am getting HTTP response code – 200 OK


Step 9: Enter the following Link and payload information and click on send. The payload is
created using the xsd file generated at Step 5.

Link: http://hansel.rapidflowapps.com:8002/webservices/rest/create_user_test/load_row

Payload:
{
"LOAD_ROW_Input": {
"@xmlns": "http://xmlns.oracle.com/apps/fnd/rest/create_user_test/load_row",
"RESTHeader": {
"xmlns": "http://xmlns.oracle.com/apps/fnd/rest/create_user_test/header",
"Responsibility":"US_HRMS_MANAGER",
"RespApplication":"PER",
"SecurityGroup":"STANDARD",
"NLSLanguage":"AMERICAN",
"Org_Id" :"204"
},
"InputParameters": {
"X_USER_NAME": "TEST_USER",
"X_ENCRYPTED_USER_PASSWORD": "Welcome123",
"X_START_DATE": "20/04/2017",
"X_EMAIL_ADDRESS": "test_user@test.com"
}
}
}

Step 10: Now to verify if a USER is created in Oracle. Query the table
FND_USER to check the result.

S-ar putea să vă placă și