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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Pitching Kotlin: An Engineering Leader's Guide to Legacy Modernization
  • Share Delta Lake Tables Between Databricks and Snowflake
  • Moving 900+ GB of Prometheus Without a Cutover Weekend
  • Architecting Production AI Across Clouds: Patterns That Decide System Survival

Trending

  • Prompt Caching for LLMs, Part 2: Semantic Caching in Production
  • Kafka Consumers on EKS: Designing for a Platform That Restarts Your Consumer Group
  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Architecture Review Boards for Generative AI: A Framework for Governance, Risk Management, and Responsible Adoption

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. The X-Factor: RAML With XML Format

The X-Factor: RAML With XML Format

Want to know more about the X-Factor? Read this article to understand how RAML can be defined for resource representation in XML format.

By 
Ruchi Saini
·
Feb. 18, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

I want X-Factor

In this article, we will explore how RAML specifications can be defined for the XML representation of resources. This will be explained with the help of JOB API. Consider this API for the purpose of getting a list of all jobs published by different companies. A job can also be posted using this JOB API.

JOB API

  • Resource: Jobs
  • Resource Path: /jobs
  • Methods:
    • GET: To retrieve a list of all jobs
    • POST:  To add a job

JSON Representation

This is how everyone talks in JSON

Let's start with JSON.  RAML Specification with media type as application/JSON is shown below:

RAML Specification with media type as application/JSON

Data type fragment of job data type:

Data type fragment of job data type

Test GET method of/jobs using Mocking Service. The response is:

Test GET method of/jobs using Mocking Service response

But now we want the representation of the job resource in XML format also.

XML Representation

Let's specify the media type as application/XML:

Specify the media type as application/XML

Test the GET method using the Mocking service. Specify the accept header value as application/XML. The response will be:

Test the GET method using the Mocking service response

Simple!! Right?

Changing Root Tag

I don't like my birth markNow we don't want our root tag to be model. So let's change it to jobs. Specify the name using XML node as shown below:

Specify the name using XML node

Test using Mocking Service again with Accept Header value as application/XML. The response is:

Test using Mocking Service again with Accept Header value as application/XML

Location Data Type

Now we want to specify the Location where this job is applicable.

I want to go places with you

So let's create a Location Data Type. Location Data Type fragment is:

Location Data Type fragment

Job Data Type is updated with Location property and it is defined using Location data type fragment:

Job Data Type is updated with Location property

Example fragments are also updated. One of the example fragments is shown below:

One of the example fragments

Test using Mocking Service again. The response is:

Test using Mocking Service response

Now, let's change the name of the location tag to JobLocation :

change the name of the location tag to JobLocation

Let's test using Mocking Service again. Now the response is:

Mocking Service response

Attributes

He is just my typeLet's make JobTitle the attribute of the job tag. So change the job data type as follows:

Change the job data typeNo change in examples. Test using Mocking Service. The response is:

Mocking Service response updated

POST Method

I am hereIn case you are wondering what the POST request looks like in our scenario, take a look:

 POST request

I have X-Factor now

JSON

JSON can you follow me?

Let's check what the GET Response looks like with JSON Representation after all these changes. Test using Mocking Service with Accept header value as application/JSON. The response is:

GET Response with JSON Representation

We have defined RAML to have resource representation in both XML and JSON.

Happy X-Factoring!

XML Data Types career Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Pitching Kotlin: An Engineering Leader's Guide to Legacy Modernization
  • Share Delta Lake Tables Between Databricks and Snowflake
  • Moving 900+ GB of Prometheus Without a Cutover Weekend
  • Architecting Production AI Across Clouds: Patterns That Decide System Survival

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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