Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention Content-Type requirement & add a second detailed example #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
app = express();

app.use(xrpc.xmlRpc);

//Note that the Content-Type: of the request must be text/xml for this to work
app.post('/RPC', xrpc.route({
echo: function (msg, callback) {
callback(null, msg);
Expand Down
30 changes: 30 additions & 0 deletions example/app-example2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var express = require('express'),
xrpc = require('xrpc'),
app = express();


app.use(xrpc.xmlRpc);

app.post('/RPC', xrpc.route({
handleNewRequest: function ( params, callback ) {
var responseObj = {
firstMember: params.firstMember,
secondMember: params.secondMember,
response: '',
action: 'end'
};

//The rest of the magic that manipulates the responseObj object e.g.
responseObj.response = 'The response string';

//Send the final response
callback( null, responseObj );
}
}));

app.listen(3000);

//Then send a request to http://localhost:3000/RPC if this is on localhost
//Sample request in ./example-2-request.xml and the expected response is shown in ./example-2-response.xml
//A very key thing to note is that Content-Type: header must be text/xml. One way to test is to use:
//curl -d @example-2-request.xml --header "Content-Type: text/xml" http://localhost:3000/RPC
1 change: 1 addition & 0 deletions example/example-2-request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>handleNewRequest</methodName><params><param><value><struct><member><name>firstMember</name><value><string>982225245516</string></value></member><member><name>secondMember</name><value><string>theValueIsThisRightHere</string></value></member></struct></value></param></params></methodCall>
26 changes: 26 additions & 0 deletions example/example-2-response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><struct>
<member>
<name>firstMember</name>
<value><string>982225245516</string></value>
</member>
<member>
<name>secondMember</name>
<value><string>theValueIsThisRightHere</string></value>
</member>
<member>
<name>response</name>
<value><string>The response string</string></value>
</member>
<member>
<name>action</name>
<value><string>end</string></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>