DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The Bill You Didn't See Coming
  • Push Filters Down, Not Up: The Data Layer Design Principle Most Developers Learn Too Late
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Jakarta NoSQL 1.0: A Way To Bring Java and NoSQL Together

Trending

  • AI in Software Development: A Mirror, Not a Magic Wand
  • Spring Boot Done Right: Lessons From a 400-Module Codebase
  • Jakarta EE Glossary: The Terms Every Java Engineer Should Actually Understand
  • How To Build a Basic RAG App
  1. DZone
  2. Data Engineering
  3. Databases
  4. Understanding the URI Param and Query Param With RAML

Understanding the URI Param and Query Param With RAML

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

By 
Jitendra Bafna user avatar
Jitendra Bafna
·
Jun. 19, 18 · Tutorial
Likes (10)
Comment
Save
Tweet
Share
280.4K Views

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.0
title: 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 API

Opinions expressed by DZone contributors are their own.

Related

  • The Bill You Didn't See Coming
  • Push Filters Down, Not Up: The Data Layer Design Principle Most Developers Learn Too Late
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Jakarta NoSQL 1.0: A Way To Bring Java and NoSQL Together

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook