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:
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:
3. Request Body
Used to send complex data like JSON payload.
Info
Request Body only applies to HTTP methods for POST, PUT, PATCH
Example:
4. Headers
Used for authentication or sending metadata.
Example:
5. Form URL Encoded (application/x-www-form-urlencoded)
Used in POST
requests when submitting data like HTML forms.
Example:
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 |