0

I have the following Backend API:

Endpoint

HTTP GET

https://localhost:8443/getSomeParameterInfo

Query Parameter

?inputAsJson

example

{
  'url': 'http://semanticstuff.org/blah#Parameter,
  'parameters_1': 'value1',
  'someArray': [
     'http://semanticstuff.org/blah#something1,
     'http://semanticstuff.org/blah#something2
  ],
  'someOtherArray': [
     'http://....'
  ]
}

the Final HTTP GET Call is

https://localhost:8443/getSomeParameterInfo?inputAsJson={aboveMentioned JSON}

Due to everchanging requirements for the Backend, the above mentioned JSON Structure keep increasing by addition of new key:value pairs. (This JSON Structure is also a query for a database)

Hinderances

Due to uses of weblinks as values it becomes necessary to use encodeURIComponent function for a successful REST Call. This means, the quotes, forward slashses etc. need to be encoded to get a Reply. This becomes quite tedious when one requires to do tests on standalone basis (using Postman or other REST Clients)

I have not seen a JSON structure passed to an API as mentioned above and hence I wish to confirm about the best practices and/or proper way to use large number of parameters when making such a RESTful call

1 Answer 1

1

I usually tend to think that getting something via a POST is a "bad" practice.

However, it sounds like body in GET is not something forbidden but still something not widely implemented in frameworks.

In your case, it will depends on how many attributes you have and the global length or your json.

If you keep on using GET method, then using an "exploded" key-value representation of your JSON should be the way to go.

Exemple:
{ "myKey": "myValue", "childObjKey": {"childObjProp": "childValue}}
could become
?myKey=myValue&childObjKey.childObjProp=childValue

But there are some limits on query parmeters' length which can be implemented in clients and/or servers. If your number of parameters is huge and values' length are unpredictable (text without length limit for instance), then using POST should be the way to go.

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

1 Comment

Here is a just an example when a user selects one Parameter from the UI. It has been URIencoded, hence a bit ugly. Once the parameters increase I guess HTTP Post would be a better option

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.