Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a C++ API, I want to send commands through http to run any c++ method from this API. I'm using libmicrohttpd.

What steps should I follow to do such a work?

share|improve this question
If the API doesn't allow for it, you can't. – Bobson Mar 21 at 15:51
what do you mean by "doesn't allow" ? – sophist Mar 21 at 15:53
@sophist: I think what he means is that you're basically asking for an eval function. Many libraries do not provide this, for obvious security reasons. You'll have to put something on the server that performs this eval function for you. – Robert Harvey Mar 21 at 16:00
@sophist - The point of an API is that it provides a defined set of function calls you're allowed to make. If the action you want to perform doesn't have an associated function call, you're out of luck. If the API doesn't accept calls in the format you want to send, you're out of luck. If you're writing the API, then that's a different story - but then you should revise the question to indicate that you want to write an API in C++ which will allow you to call arbitrary C++ code. "Interacting" with an API implies that the API already exists. – Bobson Mar 21 at 16:03
Yes, i'm creating it.. It's almost done.. The problem is how can i link those methods to libmicrohttpd.. In fact i want to send a request (ex : localhost/api/dosomething ) and this "dosomething executes a method from the api.. – sophist Mar 21 at 16:11
show 1 more comment

1 Answer

up vote 2 down vote accepted

You would write your code to listen for specific requests from your HTTP server. When one of those requests comes in you process it to get the data you need (passed as GET or POST parameters most likely) and then make the appropriate call against the C++ library that you have. You handle the return value (if there is any) to create a response that you send back to the user.

Making the request

[User] -> [GET /dosomething] -> [libmicrohttpd] => [Your Code] => [DoSomething on API.dll]

Handling the response

[DoSomething Return Value] => [Your Code] => [libmicrohttpd] => [HTTP Response] => [User]

For specifics related to libmicrohttpd have you looked at the tutorial? Chapter 3 (Exploring Requests) and 6 (Processing POST Data) seem applicable to what you are doing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.