Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6816663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:57:09+00:00 2026-05-26T20:57:09+00:00

How to model hierarchical relationship in rest api? Let’s say I want to add

  • 0

How to model hierarchical relationship in rest api?

Let’s say I want to add photo in an album, I can do this.

1

POST http://www.example.com/photo
POST http://www.example.com/album
POST http://www.example.com/addPhotoToAlbum?photoId={photoId}&albumId={albumId}

or I can do it in this way

2

POST http://www.example.com/album/{albumId}/photo/
But this way it will expose my server architecture.

or

3

POST http://www.example.com/album/addPhoto/albumId={albumId}

or

4

POST http://www.example.com/album/addPhoto/
with Json string {“albumId”:123, “photoId”:43543}

or

5

POST http://www.example.com/album/photo?photoId={}&albumId={}

REST Api is good for CRUD operation, but when it comes to how to establish relationship,
If we are following object oriented style, #2 is great. if we are following database style, #5 is great

If we are using style #2, when we want to add comments to a particular photo, should we write this
POST http://www.example.com/album/{albumId}/photo/{photoId}/comment/
or just
POST http://www.example.com/photo/{photoId}/comment/

Question: What is the general practice of establishing relationship in REST?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:57:10+00:00Added an answer on May 26, 2026 at 8:57 pm

    Here are some usefull points that help identify situations.

    http://redrata.com/restful-uri-design/

    Personally I like it when the URLS are short and ability to bookmark.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i model a hierarchical relationship in a DDD domain model? In my
I read this http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ and in nested set model I want retrieve from parent
I want to achieve the following hierarchical navigation model in a WPF MVVM application:
Essentially, I want the user to be able to define a hierarchical model, but
I have a neat Model based off QAbstractItemModel. This has a simple hierarchical tree
I have a deep hierarchical model that looks like this: Accounts -> Venues ->Events
model.py: class Tribes(Group): members = models.ManyToManyField(User, related_name='tribes', verbose_name=_('members')) i want to store a number
I love the nested-set model for storing hierarchical data, and I'd like to find
I have a Model which I am using to track permissions in a hierarchical
I have hierarchical data in a nested set model (table:projects): My table (projects): id,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.