How To Create Oracle ORDS REST webservice - APEX PLSQL
Schema: EMPLOYEE
Module: restws
Template: transfer
Handler: POST
Enable ORDS Schema
BEGIN
ORDS.ENABLE_SCHEMA(
p_enabled => TRUE,
p_schema => 'EMPLOYEE',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'restws',
p_auto_rest_auth => FALSE);
END;
/
Create ORDs Module
BEGIN
ORDS.DEFINE_MODULE(
p_module_name => 'emp.v1',
p_base_path => '/emp.v1/',
p_items_per_page => 25,
p_status => 'PUBLISHED',
p_comments => NULL);
END;
/
Create ORDS Templates
BEGIN
ORDS.DEFINE_TEMPLATE(
p_module_name => 'emp.v1',
p_pattern => ‘create’,
p_priority => 0,
p_etag_type => 'HASH',
p_etag_query => NULL,
p_comments => NULL);
END;
Create ORDS Handler
BEGIN
ORDS.DEFINE_HANDLER(
p_module_name => 'emp.v1',
p_pattern => 'update',
p_method => 'POST',
p_source_type => 'plsql/block',
p_items_per_page => 0,
p_mimes_allowed => '',
p_comments => NULL,
p_source =>
'BEGIN
- call any plsql package or do insert/update .....
status := 'OK';
END;'
END;
/
Add Response Params
BEGIN
ORDS.DEFINE_PARAMETER(
p_module_name => 'asset.track.v1',
p_pattern => 'transfer',
p_method => 'POST',
p_name => 'X-APEX-STATUS-CODE', -- or any Name
p_bind_variable_name => 'status',
p_source_type => 'RESPONSE',
p_param_type => 'INT',
p_access_method => 'OUT',
p_comments => NULL);
END;/