




class ZCL_HTTP_SERV definition
public
create public .
public section.
interfaces IF_HTTP_SERVICE_EXTENSION .
protected section.
private section.
ENDCLASS.
CLASS ZCL_HTTP_SERV IMPLEMENTATION.
method IF_HTTP_SERVICE_EXTENSION~HANDLE_REQUEST.
response->set_text( 'Hi Bloggers , The HTTP service is Up and Running' ).
endmethod.
ENDCLASS.

| request | Incoming request object for an HTTP Service. | |
| response | Outgoing response object for an HTTP Service | |


CLASS zcl_http_serv DEFINITION
PUBLIC
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_http_service_extension . "Standard Interface
PROTECTED SECTION.
PRIVATE SECTION.
METHODS: get_html RETURNING VALUE(html) TYPE string. "GET Request HTML Generator Method
METHODS: post_html "POST Request HTML Generator Method
IMPORTING
First_Name TYPE string
Last_Name TYPE string
Designation TYPE string
Company TYPE string
Phone_Num TYPE string
RETURNING VALUE(html) TYPE string.
CLASS-DATA url TYPE string.
ENDCLASS.
CLASS zcl_http_serv IMPLEMENTATION.
METHOD if_http_service_extension~handle_request. "Standard Method Which Handles the HTTP request
url = 'https://45f514af-f57b-4579-990b-8b70ea328491.abap-web.us10.hana.ondemand.com:443/sap/bc/http/sap/z_http_serv/?sap-client=100'. " URL For the HTTP service #Generated while creation
CASE request->get_method( ). "Getting the request's HTTP method ie GET , POST ,PUT , PATCH ,DELETE Etc .
WHEN CONV string( if_web_http_client=>get ). "if its a GET Request
response->set_text( get_html( ) ). " Sets the response text as an HTML file , so that the browser could show a web page as response.
WHEN CONV string( if_web_http_client=>post ). "if its a Post Request
DATA(First_Name) = request->get_form_field( `fname` ). "gets the parameters values Sent by POST request Using the parameter name
DATA(Last_Name) = request->get_form_field( `lname` ).
DATA(Designation) = request->get_form_field( `Designation` ).
DATA(Company) = request->get_form_field( `Company` ).
DATA(Phone_Num) = request->get_form_field( `phno` ).
response->set_text( post_html(
EXPORTING First_Name = First_Name "Sets the response text as an HTML file , so that the browser could show a web page as response .
Last_Name = Last_Name
Designation = Designation
Company = Company
Phone_Num = Phone_Num
) ).
ENDCASE.
ENDMETHOD.
METHOD get_html. "Response HTML for GET request
html = |<html> \n| &&
|<body> \n| &&
|<title>Registration Form </title> \n| && " The HTML page has few input fields and a submit button while clicking the submit button the page sends the
|<form action="{ url }" method="POST">\n| && " values entered in the input fields as a POST request .
|<H2>Blogger Registration</H2> \n| &&
|<label for="fname">First name: </label> \n| &&
|<input type="text" id="fname" name="fname" required ><br><br> \n| &&
|<label for="lname">Last name:</label> | &&
|<input type="text" id="lname" name="lname" required ><br><br> \n | &&
|<label for="Designation">Designation:</label> | &&
|<input type="text" id="Designation" name="Designation" required ><br><br> \n | &&
|<label for="Company">Company:</label> | &&
|<input type="text" id="Company" name="Company" required ><br><br> \n | &&
|<label for="phno">Phone Number:</label> | &&
|<input type="number" id="phno" name="phno" required ><br><br> \n | &&
|<input type="submit" value="Submit"> \n| &&
|</form> | &&
|</body> \n| &&
|</html> | .
ENDMETHOD.
METHOD post_html. "Response HTML for POST request
html = |<html> \n| &&
|<body> \n| &&
|<title>Registration Form </title> \n| && " HTML page is the response page after the submit happens from First page
|<form action="{ url }" method="Get">\n| &&
|<H2>Blogger Registration Success </H2> \n| &&
|<p> Thanks { First_Name } { Last_Name } working for { Company } company as { Designation }, </p> | &&
|<p> for Registering with knowledge sharing BLOGS Platform. We will contact you on { Phone_Num } for further process. </p> | &&
|<input type="submit" value="Go Back"> \n| &&
|</form> | &&
|</body> \n| &&
|</html> | .
ENDMETHOD.
ENDCLASS.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 33 | |
| 33 | |
| 30 | |
| 28 | |
| 26 | |
| 26 | |
| 20 | |
| 15 | |
| 11 | |
| 11 |