Skip to main content
Tweeted twitter.com/StackSoftEng/status/1565897667334610950
Question Protected by gnat
deleted 5 characters in body
Source Link
Chris
  • 173
  • 1
  • 4

My app has an API endpoint GET /sessions/{id} which gets info about a session. This endpoint returns a lot of data, so we allow passing JSON in the request body to filter what fields etc. are requested. I know GET requests should not include request body, so I am trying to convert it to POST but not sure what to call the endpoint now:

  • POST /sessions/{id} (but this looks like it's modifying the session, which it doesn't do)
  • POST /session_info/{id} (to make it clear that we are just querying info)
  • POST /session/{id}/info

Example use:

GET /sessions/42

request body:

{'participants': ['jsmith', 'bjones'], 'participant_fields': ['dob', 'zip']}`

response:

{
    'id': 42, 
    'date': '2022-08-29', 
    'room': 15, 
    'participants': [
        {'id': 'jsmith', 'dob': '1985-01-06', 'zip': 04843},
        ...
    ],
    ...
}

(participants and participant_fields are optional; if omitted it will return all data about all participants.)

I know GET requests should not include request body, so I am trying to convert it to POST but not sure what to call the endpoint now:

  • POST /sessions/{id} (but this looks like it's modifying the session, which it doesn't do)
  • POST /session_info/{id} (to make it clear that we are just querying info)
  • POST /session/{id}/info

(I know the filter params could be encoded as query string but I just think it's easier for my users to use JSON.)

Any advice?

My app has an API endpoint GET /sessions/{id} which gets info about a session. This endpoint returns a lot of data, so we allow passing JSON in the request body to filter what fields etc. are requested:

Example use:

GET /sessions/42

request body:

{'participants': ['jsmith', 'bjones'], 'participant_fields': ['dob', 'zip']}`

response:

{
    'id': 42, 
    'date': '2022-08-29', 
    'room': 15, 
    'participants': [
        {'id': 'jsmith', 'dob': '1985-01-06', 'zip': 04843},
        ...
    ],
    ...
}

(participants and participant_fields are optional; if omitted it will return all data about all participants.)

I know GET requests should not include request body, so I am trying to convert it to POST but not sure what to call the endpoint now:

  • POST /sessions/{id} (but this looks like it's modifying the session, which it doesn't do)
  • POST /session_info/{id} (to make it clear that we are just querying info)
  • POST /session/{id}/info

(I know the filter params could be encoded as query string but I just think it's easier for my users to use JSON.)

Any advice?

My app has an API endpoint GET /sessions/{id} which gets info about a session. This endpoint returns a lot of data, so we allow passing JSON in the request body to filter what fields etc. are requested. I know GET requests should not include request body, so I am trying to convert it to POST but not sure what to call the endpoint now:

  • POST /sessions/{id} (but this looks like it's modifying the session, which it doesn't do)
  • POST /session_info/{id} (to make it clear that we are just querying info)
  • POST /session/{id}/info

Example use:

GET /sessions/42

request body:

{'participants': ['jsmith', 'bjones'], 'participant_fields': ['dob', 'zip']}`

response:

{
    'id': 42, 
    'date': '2022-08-29', 
    'room': 15, 
    'participants': [
        {'id': 'jsmith', 'dob': '1985-01-06', 'zip': 04843},
        ...
    ],
    ...
}

(participants and participant_fields are optional; if omitted it will return all data about all participants.)

I know the filter params could be encoded as query string but I just think it's easier for my users to use JSON.

Any advice?

Source Link
Chris
  • 173
  • 1
  • 4

What to name a POST endpoint that behaves like GET?

My app has an API endpoint GET /sessions/{id} which gets info about a session. This endpoint returns a lot of data, so we allow passing JSON in the request body to filter what fields etc. are requested:

Example use:

GET /sessions/42

request body:

{'participants': ['jsmith', 'bjones'], 'participant_fields': ['dob', 'zip']}`

response:

{
    'id': 42, 
    'date': '2022-08-29', 
    'room': 15, 
    'participants': [
        {'id': 'jsmith', 'dob': '1985-01-06', 'zip': 04843},
        ...
    ],
    ...
}

(participants and participant_fields are optional; if omitted it will return all data about all participants.)

I know GET requests should not include request body, so I am trying to convert it to POST but not sure what to call the endpoint now:

  • POST /sessions/{id} (but this looks like it's modifying the session, which it doesn't do)
  • POST /session_info/{id} (to make it clear that we are just querying info)
  • POST /session/{id}/info

(I know the filter params could be encoded as query string but I just think it's easier for my users to use JSON.)

Any advice?