Skip to content

Passing Parameters to a REST API

When working with REST Providers-APIs, parameters can be passed in several ways depending on the Provider/API's design and the HTTP method used.


1. Query Parameters

Used for filtering, searching, or pagination.

Example:

GET /api/products?category=books&sort=price_desc

Related MDRFRAME Functions:

Example API Code

dcl-s category  varchar(20) inz;
dcl-s sort      varchar(50) inz;

category = MDR_getQueryVar(handle: 'category');
sort     = MDR_getQueryVar(handle: 'sort');

category will equal books sort will equal price_desc


2. Path Parameters

Embedded in the URL path, often used to identify a specific resource.

Example:

GET /api/users/123


3. Request Body

Used to send complex data like JSON payload.

Info

Request Body only applies to HTTP methods for POST, PUT, PATCH

Example:

POST /api/users
Content-Type: application/json

{
  "name": "Alice",
  "email": "alice@example.com"
}


4. Headers

Used for authentication or sending metadata.

Example:

GET /api/profile
Authorization: Bearer <your_token>


5. Form URL Encoded (application/x-www-form-urlencoded)

Used in POST requests when submitting data like HTML forms.

Example:

POST /api/login
Content-Type: application/x-www-form-urlencoded

username=alice&password=secret123


Summary Table

Method Used For Where Example
Query Params Filtering, pagination URL /products?type=phone
Path Params Identify specific resource URL path /users/123
Body (JSON) Complex data input Request { "name": "Alice" }
Headers Meta info (auth, content-type) Request Authorization: Bearer token123
Form URL Encoded Submit form-style data Request username=alice&password=secret123