Is there a way to specify a JSON schema (ie not pydantic models) for the request body and use the automated documentation features (ie to have "Try it out" with support for that schema) ?
I solved the problem by building a rapidoc based web page, that consumes the JSON (or YAML) openapi specification and generates the HTML contents on the client side.
Related
I'm doing some server-side table generation to support pagination, searching, and so. On the client side, I'm using the datatable.js library. This library sends out GET requests in the form like this:
GET /api/data?draw=22&columns%5B0%5D%5Bdata%5D=name&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=age&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=address&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=false&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=phone&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=false&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=email&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=30&length=10&search%5Bvalue%5D=ass&search%5Bregex%5D=false&_=1635453433852 HTTP/1.1
What would be the preferred way to map these query params into a pydantic object with proper validation? Some of these values are potentially used in a SQL query.
Here is the documentation for all the params:
https://datatables.net/manual/server-side
I have to write sign on peoplecode to make a service call by passing token (sent from third party) to API and get the responce (if token is valid responce will have username) in json format to create a PS_TOKEN.
I am fresher to peoplecode. How can I run HTTP POST request by passing token and get the response using Peoplecode?
You would create a synchronous service operation in the Integration Broker. The Integration Broker works best if you are sending XML or JSON. If this is just a regular HTTP POST with fields then it can cause some issues with the Integration Broker. I had a similar case and could not get the basic HTTP Post to work but instead ended up using HTTP POST multipart/form-data and was able to get that to work.
Steps I had to do to make this work.
Create a Message (document based or rowset based are both possible)
Create Service Operation and related objects
Create Transform App Engine to convert the Message to a HTTP POST multipart/form-data
Create a routing and modify the connector properties to send the content type of multipart/form-data. Also call the Transform app engine as part of the routing.
The issue with a application/x-www-form-urlencoded POST is that it seems PeopleSoft does another url encoding after the Transform, which is the last time you can touch the output with code. This final url encoding was encoding the = sign in the form post which made the format invalid.
Your other option would be to write this is Java and call the Java class from within PeopleSoft (or mix the Java objects in with PeopleCode). If you choose to go this way then the App Server needs to have connectivity to your authentication server. My only experience with this is I had a client that used this approach and had issues under heavy load. It was never determined the cause of the performance issue, they switched to LDAP instead to resolve the issue.
I working on a REST service based on the 'WCF REST Service template' in VS2010. Out-of-the-box, you can have a service return XML or JSON, based on the Accept type specified in the request, but how do I add my own format....
I found an example:
http://msdn.microsoft.com/en-us/library/ee476510.aspx
where you test the Accept header in the method, and return Message based on that type, however I don't really like to implement this in all my service methods.
What I'd really like is a way where I could annotate (attribute) my DataContract with a formatter/serializer for each kind of Content-Type that I want to support, and then framework call my formatter/serialiser when asked for a Content-Type not supported out-of-the-box.
Are there already some extensionpoints, in the WCF REST Service framework, for doing this??
Any help would be greatly appreciated
TIA
Søren
WcfRestContrib should be able to do this via Formatters. It provides set of build in formatters for XML, JSON, URL encoded form posts and it also allows creating custom formatters.
Built in webHttpBinding in WCF doesn't have this functionality at the moment - it allows only appliation/json and text/xml negotiation and other content types can be mapped to these two via custom content type mapper.
"Attributes" for response formatting are only available for syndication where it works little bit differently. Service must always return SyndicationFeedFormatter and known types allow defining multiple derived formatters for Atom or Rss.
I am confused on one thing. As I have read web services use SOAP protocol for communication and it is an XML based protocol; I was expecting the classical HelloWorld method on an asp.net web service to return an xml based data.
But when I checked with Fiddler i see that the Response Textview has a JSON string instead of an XML structure like:
{"d":"Hello World"}
Does this mean that asp.net web-service implementation returns 'string' types embedded as a value of a property called 'd' ?
Web services don't have to use SOAP as the protocol. The WCF lets you use all sorts of protocols for your web services. SOAP and JSON are just 2 of the options.
ASMX services return JSON if you request them via POST, with a content-type containing application/json. More info here: http://encosia.com/2010/03/03/asmx-and-json-common-mistakes-and-misconceptions/
Their return value isn't limited to just strings either. If you return a collection type, you'll get a JSON array. If you return a server-side class, that will be serialized into the correct JSON key/value pairs to represent that object.
The .d is sort of an orthogonal issue. It's a security feature to thwart a particular attack against JavaScript's Array constructor. More here: http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/
Ok. I have found my answer, here:
"ASP.NET AJAX sends JSON messages to Web Services as opposed to the standard Simple Object Access Protocol (SOAP) calls typically associated with Web Services. This results in smaller request and response messages overall. It also allows for more efficient client-side processing of data since the ASP.NET AJAX JavaScript library is optimized to work with JSON objects. "
More details in :
http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-web-services
As you can see here JSON responses are supported by recent releases of the .NET Framework.
hey guys i have a restful xml service where client passes current version of html they are viewing. if the version on the server is the same as the client, i just respond with the current server version in xml. example: <Response ServerHTMLVersion="1" />
however if server html version is greater than current client version, i still spit out the same response like above like <Response ServerHTMLVersion="2" />. but problem being my client application needs to do a seperate http request to download the html file incase response xml version is greater than clients version
for performance reasons, i wanted to cut down this http request and i wanted to know what is the best way to do this. should i simply encode the html to make it xml safe and append that with xml response - problem with this being html is FAT and encoding makes it even fatter
OR
is there a better way of managing this? note that i am already gziping my response for both, xml as well as html right now
i wanted to know the way to do this keeping performance in mind. the restful xml service is implemented via asp.net 3.5 and iis 7
Have you thought about using HTTP headers? Since really the primary data here is the HTML, and the ServerHTMLVersion is a sort of "meta data" about that html, it should work.
Personally, I'd make the response to the request 1) blank when the versions match and 2) the HTML for non-matching versions; then, use the Pragma HTTP header to send something like Pragma: "ServerHTMLVersion=2". By doing this, you can easily check if the client and server versions differ, and just grab the full response if they're different.
Some people would debate the idea of returning HTML from a REST service, but I personally would consider this totally valid, and an nice clean way of separating your meta data from the actual user data.
-Jerod