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

  • SEARCH
  • Home
  • 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 8300989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:46:04+00:00 2026-06-08T16:46:04+00:00

1) How to work with relationships? Let’s say I’ve an Article resource, which is

  • 0

1) How to work with relationships?

Let’s say I’ve an Article resource, which is written by an Author.

Basically I’ll have something like :

{
    "article": {
        "id": 1,
        "title": "Foo bar",
        "body": "Lorem ipsum dolor sid amet",
        "published_on": "2011-05-06 21:54:23",
        "author": {
            "id": 25,
            "username": "johndoe"
        }
    }
}

I’ll access my resource at api/articles/1

My question is, what is the best way to represent this data?

Should I do something like:

{
    "article": {
        "id": 1,
        "title": "Foo bar",
        "body": "Lorem ipsum dolor sid amet",
        "published_on": "2011-05-06 21:54:23",
    }
}

And access author by calling api/articles/1/author

Only include author id (subobject identifier)

{
    "article": {
        "id": 1,
        "title": "Foo bar",
        "body": "Lorem ipsum dolor sid amet",
        "published_on": "2011-05-06 21:54:23",
        "author": {
            "id": 25,
        }
    }
}

Or including the full relationship as seen above?


2) PUT or POST to create new object?

Looking on SO and elsewhere, I’ve noted that both are used to create and/or update object.

As far as I understand, both are valid action but it depends on the context. If I create a subobject related to a previously created object I’ve to use POST.

Ex: I create a vote for an article, as the Article already exists, I’ll POST a new vote, however, if I create a new Article, I PUT it.

Am I right?


3) How should we format Date?

I’ve seen that SO use Unix Timestamp, where ISO8601 are mostly used elsewhere.

Is there any “standard” or recommandation about this?

  • 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-06-08T16:46:06+00:00Added an answer on June 8, 2026 at 4:46 pm
    1. How to work with relationships?

    Your first approach isn’t very good because it does not allow to discover the author – probably something you want to know.

    The second approach is valid, but requires you to know the URI pattern to lazily fetch author in advance, e.g. api/author/25.

    Third approach is fine as long as you don’t have one-to-many relationships (the size of the document grows exponentially) or very large nested objects.

    The fourht approach, advocated by several people, is to employ hateos principle by using hyperlinks rather than abstract identifiers or full documents.

    1. PUT or POST to create new object?

    There is no confusion here. POST is always used to create new object while PUT should update existing one (or possibly create one if it doesn’t exist. Bottom line: every time you call POST, you change the state of the system (resource). However you can call PUT multiple times (idempotency – great when you want to safely retry).

    Note that POST links typically do not contain ids (e.g. POST api/articles) while PUT DO: PUT api/articles/42. If you know the ID, the entity probably already exists.

    1. How should we format Date?

    Both UNIX timestamps and iso8601 are fine. I am not sure if there is any standard appart from JSON schema recommendations:

    5.23. format

    […]

    date-time This SHOULD be a date in ISO 8601 format of YYYY-MM-DDThh:mm:ssZ in UTC time. This is the recommended form of date/
    timestamp.

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

Sidebar

Related Questions

Let's say I have two tables ( Address and Phone ) in sql which
Let say I have a class like this: public sealed class Foo { public
Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit
I have a couple of tables where there are one to many relationships. Let's
Let say I have two tables with a many-to-many relationship (i.e. there is a
Let's say that I have following situation. I have many customers and many consultans,
I have a situation like this: there are three Django models, let's call them
I have a question on making a good subquery for this problem Let's say
Let's say we have a database with a table that has many other associated
Let's say I have a Store and a Product entity, with a many-to-many relationship

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.