I want to use mongoose for exposing rest apis from inside my aplication. However, I do not see any model of how this can be implemented.
Does anyone knows if it's possible of feasible to do using mongoose?
Can any exemple be provided demonstrating a simple case of it?
I've used mongoose to implement an HTTP interface to a Windows service in C++. It was fairly straightforward to wrap mongoose in a set of C++ classes. It's easy to retrieve request information and generate output streams. I used Boost.IOStreams to implement connection streams so that request handlers could use a std::ostream interface to write results back to the connection.
Use the set_uri_callback() function to define a handler for every possible request.
In each handler get the request type (GET, PUT, POST, etc.) and parameters.
Write the appropriate result back to the connection.
Related
I have a gRPC server written in C++ and I would like to trace or log all RPC calls to the server, including arguments and responses, if possible.
The Go gRPC implementation has the very helpful concept of an Interceptor that can be attached to a client or a server. The interceptor gets access to not only the metadata, but also to the arguments/responses. For the C++ API I cannot find anything similar.
What about https://grpc.github.io/grpc/cpp/classgrpc_1_1experimental_1_1_interceptor.html ?
The only usage reference I could find is this SO question: C++ grpc::experimental:interceptor how to return status and message from custom interceptor
EDIT: in matter of fact, I think this is a better resource - https://github.com/grpc/grpc/blob/7bf82de9eda0aa8fecfe5edb33834f1b272be30b/test/cpp/end2end/server_interceptors_end2end_test.cc
I think you can query the request & response messages from the methods argument of the interceptor overridden method Intercept(grpc::experimental::InterceptorBatchMethods* methods), see available methods and properties here: https://grpc.github.io/grpc/cpp/classgrpc_1_1experimental_1_1_interceptor_batch_methods.html
I know how to implement a server with Mongoose, in fact all information that I could find was about servers, but I need to know how do I implement a client.
Very basic, how to connect to a server is the main problem, the send functions are pretty straight forward.
Mongoose is a web server and AFAIK does not provide an API for client side http requests.
For C++ http client libraries, you might want to look at these answers:
What C++ library should I use to implement a HTTP client?
A better C++ HTTP client library
These sites also give a good overview about available C++ client libraries:
http://curl.haxx.se/libcurl/competitors.html
http://en.cppreference.com/w/cpp/links/libs
Mongoose actually does provide HTTP client functionality. See mg_connect() on http://cesanta.com/docs/API.shtml. Also, example HTTP client code is at https://github.com/cesanta/mongoose/tree/master/examples/http_client
I suggest using Fossa library (a superset of Mongoose), as it's HTTP client interface is more flexible. Example code is at https://github.com/cesanta/fossa/tree/master/examples/restful_client , documentation is at http://cesanta.com/docs/fossa/
I found this little library to be perfect solution for my problem. It allows you to stub REST service responses easily.
Now i need to replicate the same set of test cases in PHP version of our library. Do you know any similar library/framework in PHP?
You could use Guzzle. Guzzle is a PHP HTTP client & framework for building RESTful web service clients. The thing is that you can create Response objects. In this library, you have a Response class. You could just create the Guzzle Response that you want (choosing the desired status code, content, etc), and mock your HTTP Client so it returns the Response object that you just created.
If you read the documentation, it seems that there is a plugin to mock responses, although I've never used it.
I am reading so many things to understand various things in WCF.
Very soon, actually, i want to move/convert existing WSE3 web services to WCF. In existing WSE web services, I have some (data) classes that model entities in our environment.
While transforming those classes, should I use Data Contract/Data Member attribute or the MessageContract attribute?
1. How to decide between Message Contract and Data Contract in WCF?
2. Does type of binding (like basicHttpBinding) has any role in this decision?
3. Does proxies created at client side (when we add web reference) change significantly depending on the Data or Message Contract?
(PS: I am trying to find a way so that existing WSE clients should be able to consume the WCF service without much alterations/modifications. Is it possible to use the current proxies generated from ASMX web services, to connect to the new WCF service just by setting URL of the proxy to WCF service?)
Here is a quick go at answering your questions:
1) Unless there is a specific reason like tweaking the structure of the soap XML, use DataContract instead of MessageContract.
2 & PS) Since you are currently using soap over HTTP, you'll most likely need the new services to be configured for basicHttpBinding. This will provide the interoperability that you need for the ASMX clients.
3) It shouldn't if the soap structure created by the WCF service matches your current soap.
I vaguely remember that WSE 3.0 supported some of the WS-* standards. If your current code depends on these then you may be able to also expose a wsHttpBinding for these operations but I don't think a default ASMX client works with a wsHttpBinding configured service.
It depends on control you need over resulting SOAP message. DataContract defines part of message body wrapped by element defined by operation. MessageContract defines a structure of whole message - you can use multiple body members, you don't have to use default wrapper element and you can also place some data into SOAP headers.
In your scenario the most important part is to define WCF to use same SOAP messages as your former WSE3 service. Here the important is how do you currently serialize data? If you use Xml serialization (and attributes) you can use it directly in WCF by switchinig from data contract serialization to xml serialization.
Btw. why did you use WSE3 instead of plain ASMX? Did you use message security? In such case you will need another binding. BasicHttpBinding is not able to do message security.
General answer is yes, you can create service wich your current client proxies will be able to consume. But in reality the effort depends on your current service and current code.
I am looking to make a service agent in C# from scratch. If the contracts/XSD are shareable via WSDL or dll. How do I go about writing a light weight service agent that can be configured to make calls to the SOAP webservice. When you do an add reference I feel too much code is generated behind my back.
You can post data to a webservice using the following url structure:
http://mydomain.com/mywebservicedirectory/mywebservice.asmx/mywebservicemethod
Simply use an HTTP POST to pass data(typically xml/json) to the service and process the response.
I use a bassic soap template and XSLT to render it out for what I want. It isn't that fun if you need to call multiple methods. I'm simply calling the same method over and over so it's no big deal. Simple HTTP POST will do it, that's all WCF/ASMX does.
You can get the WSDL and use XSD.exe to generate the object classes for you.