Understanding the URI Param and Query Param With RAML - DZone (2024)

  1. DZone
  2. Data Engineering
  3. Databases
  4. Understanding the URI Param and Query Param With RAML

Look at how and when to use URI parameter and Query Parameter with RAML.

By

Understanding the URI Param and Query Param With RAML - DZone (1)

Understanding the URI Param and Query Param With RAML - DZone (2) CORE ·

Jun. 19, 18 · Tutorial

Join the DZone community and get the full member experience.

Join For Free

1.0 Introduction

It is very important to know when to use Query Parameter or URI Parameter while designing an API. URI parameter (Path Param) is basically used to identify a specific resource or resources whereas Query Parameter is used to sort/filter those resources.

Let's consider an example where you want identify the employee on the basis of employeeID, and in that case, you will be using the URI param.

GET /employee/{employeeID}

Take another example where you want to filter the employee on the basis of designation, and in that case, you will be using Query Parameter.

GET /employee?designation=SSE

Return list of car having color black GET /cars?color=black
Return list of cars sorted by model GET /cars?sortBy=model
Return list of drivers for car 888 GET /cars/{car-number}/drivers
GET /cars/car888/drivers
Return employees having employeeID 10 GET /employees/{employeeID}
GET /employees/10

2.0 Defining URI Parameter With RAML

URI Parameter is a variable element enclosed in curly braces {} inside relative URI of resources.

/employees: /{employeeID}: description: Return employee information on basis of EmployeeID get: responses: 200: body: application/json: example: | {"employeeID":"1", "employeeName":"Tom Berry","designation":"SSE"}

Looking at above RAML, the URL to get employee details on the basis of employeeID will be GET /employees/{employeeID}where employees is resource and {employeeID} is URI parameter.

3.0 Defning the Query Parameter With RAML

Query Parameter is basically used to filter or sort the resources. It is passed in the URL as query string in key-value form.

/employees: get: queryParameters: designation: description: Desgnation of employee type: string required: true responses: 200: body: application/json: example: | {"employees":[ {"employeeID":"1", "employeeName":"Tom Berry","designation":"SSE"}, {"employeeID":"2", "employeeName":"JAck Jones","designation":"SSE"} ]}

Looking at the above RAML, the URL to get employee details having designation SSE will be GET /employees?designation=SSE.

In the above example, query parameter designation is mandatory and even you can make it optional by modifying the required to false.

4.0 Final RAML With URI Parameter and Query Parameter

#%RAML 1.0title: Employees/employees: get: queryParameters: designation: description: Desgnation of employee type: string required: true responses: 200: body: application/json: example: | {"employees":[ {"employeeID":"1", "employeeName":"Tom Berry","designation":"SSE"}, {"employeeID":"2", "employeeName":"JAck Jones","designation":"SSE"} ]} /{employeeID}: description: Return employee information on basis of EmployeeID get: responses: 200: body: application/json: example: | {"employeeID":"1", "employeeName":"Tom Berry","designation":"SSE"}

Now you know when and how to use URI parameter and Query Parameter With RAML.

Uniform Resource Identifier Database

Opinions expressed by DZone contributors are their own.

Related

  • How To Connect a Heroku Java App to a Cloud-Native Database

  • How to Access URI and Query Parameter Inside Kumologica API

  • Strategies for Effective Shard Key Selection in Sharded Database Architectures

  • Organizing Knowledge With Knowledge Graphs: Industry Trends

Understanding the URI Param and Query Param With RAML - DZone (2024)
Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5895

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.