0

I am building an Asynchronous API with polling and it has the following endpoints -

  1. POST Create Resource
Request - 

curl -X POST https://api.example.com/v1/card/eligibility/

Response - 
{
  "requestId": "12345678",
  "timestamp": "2021-11-01",
  ...
}

  1. GET Fetch Resource - we can use it for polling top
Request - 
curl -X GET https://api.example.com/v1/card/eligibility/12345678

Response - 
{
   eligibilityStatus: Eligible/Ineligible 
   orderData: abc
   ..
}

Can I expose a separate GET endpoint working on the same requestId to run a function over the same resource?

3rd endpoint

Request - 
curl -X GET https://api.example.com/v1/card/product-eligibility/12345678

Response - 
{
   product-eligibility: 111
   orderData: abc
   ..
}

1 Answer 1

0

If you want to follow Domain Driven Design, you will first have to model your domain.

For a REST API, your paths should reflect the models in your domain. If you have a "card" model, then you expose the operations on this model at a /card endpoint, which you already have.

There is not a lot of information about your domain in your question, but I will try to answer with some assumptions.

A card might have an eligibility, and eligible products that can be bought with it, which should be reflected in the responses to GET /card

So you would POST /card and receive a response reflecting the model that you just created:

{
    "id": "12345678",
    "createdOn": "2021-11-01T00:00:00Z",
    "eligible": true,
    "eligibleProducts": [
        111
    ]
}

You now have an ID that you can query at /card/:id.

For example GET /card/12345678, which will give you the model response:

{
    "id": "12345678",
    "createdOn": "2021-11-01T00:00:00Z",
    "eligible": true,
    "eligibleProducts": [
        111
    ]
}

For the concept of "product eligibility" or "order" and how these tie into your "card" model and what the relationships between these models are, there is simply not enough information about your domain in your question to give an appropriate answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.