JSON-RPC 2.0 Response params in the URI endpoint, instead of request body

133 views
Skip to first unread message

Raymund

unread,
Aug 31, 2019, 12:25:53 PM8/31/19
to JSON-RPC
Greetings JSON-RPC Group,

Based on the 'params' member of the 'Request Object', the params may be omitted.

Is it then still in compliance with JSON-RPC 2.0 if the procedure call in the form of class.method be placed in the URI endpoint - the first string being the class, and the second string being the method?

Example: POST /person/update/1

where 'person' is the 'Person Class' and 'update' is the 'update' method inside the class, and 1 as the resource ID?

I am developing a REST-like RPC that does not depend on HTTP verbs, and would like to follow JSON-RPC 2.0 specs.

Thank you,

Raymund

Martin Barker

unread,
Aug 31, 2019, 1:43:18 PM8/31/19
to json...@googlegroups.com
Hi Raymund,

The whole point is JSON-RPC is not REST, REST is HTTP Compatible, where as JSON-RPC is not, having built a JSON Restfull API you should be looking at defining and creating JSON-Schema's  https://json-schema.org/specification.html

You could make your system both restfull and JSON-RPC compatible as Separate Executions E.G POST to / Check the POST Body for JSON-RPC is valid to the Schema,  https://github.com/fge/sample-json-schemas/tree/master/jsonrpc2.0 if it's not then Allow your router to fire for /controller/method/..params

Otherwise the other option is your make your system only JSON-RPC compatible and the Rest System just acts as a wrapper rewriting the request to JSON-RPC request then passing it to the handler.


I hope this makes sense.  

--
You received this message because you are subscribed to the Google Groups "JSON-RPC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-rpc+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/json-rpc/253e561e-50d0-45d8-9cec-97d1108aa4d7%40googlegroups.com.

Raymund

unread,
Aug 31, 2019, 7:48:57 PM8/31/19
to JSON-RPC
Hi Martin,

According to the Overview section of JSON-RPC 2.0, it can be used over http. I guess the usual manner of using RPC in http it is to assign the class.method as the method member, and that there is only one endpoint to access, just like GraphQL.

If I am correct and JSON-RPC can be used over http, I would suggest to make the method member of the request object more flexible. Like if the protocol is http, it would be acceptable to leave the request method member blank or assign as null, and let the request URI handle the call to class.method. The request and response object members would still be the same.

Just a suggestion though.

Many thanks,

Raymund

Leo Noordergraaf

unread,
Sep 1, 2019, 5:04:50 PM9/1/19
to JSON-RPC
JSON-RPC is carrier neutral so you can also use it over HTTP.
What you are suggesting is possible of course but it wouldn't be JSON-RPC anymore.

Do not expect other JSON-RPC client or server software to work with your implementation.

Raymund

unread,
Sep 2, 2019, 3:52:58 AM9/2/19
to JSON-RPC
API with a single URI endpoint would comply with v2.0 specs since 'class.method' can be included as the method member.

For multiple endpoints, I would follow Martin's suggestion to still include a method member (not null) to comply with v2.0 schema. This way, it can adhere to both REST and JSON-RPC. REST for URI endpoints and JSON-RPC for schema of data being exchanged.

Thank you.

Martin Barker

unread,
Sep 2, 2019, 10:11:05 AM9/2/19
to json...@googlegroups.com
Yeah, sorry about that I was on my phone and was trying to think of the best way to say that REST is designed for HTTP, JSON-RPC is not it can use any transmission method, it's not specifically built for HTTP nd what you initially said would break the spec because you would be making JSON-RPC HTTP Reliant and that is then not compatible with the spec. 

Like I said and you seem to have come to the same conclusion you can make a single system both JSON-RPC and REST Compatible, So in MVC terminology,

your default controller checks for JSON-RPC POST Payload if there handle it, if not give Invalid API Call Error You can use the JSON RPC error layout for that, then if they go to any address E.G /item/{item_id:\\d+} then your actual Code sits in a model and both your Routed (REST) routes use the models, and your JSON-RPC on '/' uses a model to process the payload and call the correct class and method.

Kind Regards
Martin Barker

--
You received this message because you are subscribed to the Google Groups "JSON-RPC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-rpc+u...@googlegroups.com.

Raymund

unread,
Sep 3, 2019, 6:27:00 PM9/3/19
to JSON-RPC
Hi Martin,

I was able to apply the concept to the nano-framework I am developing, and it does work.


It is JSON-RPC-first, then REST-RPC (REST-like) with automatic /class/method routing, then RESTful with /resource/1 endpoints as defined.

To remove compatibility layers is a matter of commenting or deleting the layer scripts.

Regards,

Raymund
Reply all
Reply to author
Forward
0 new messages