ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.43k stars 889 forks source link

How to create API's using, C++ crow web-framework #388

Closed saivamsi98 closed 3 years ago

saivamsi98 commented 3 years ago

I am new to C++, I am trying to implement web-server using C++ crow web-framework. The main task is to create GET and POST API's using 'crow' framework. I already have a JSON file that is created using cJSON library, What need to be implemented is,

1)GET API need to access the sample.json file and need to show the information present in that file.

And, suppose, if we made any changes in the sample.json file,

2)By using, POST API we need to update the changes in that file.

This is the sample.json:- ``

{ "log_enable": 1, "log_level": 1, "device": [ { "server_ip": "10.27.15.168", "server_port": "17001", "http_max_users": "16", } ],
"user": [ { "username": "user", "password": "123456" } ], "proxy": [ { "suffix": "proxy", "url": "rtsp://10.27.15.178/proxyStreamer_profile_1", "user": "admin", } ] } ``

I have seen the github examples, but not able to understand how this crow framework works to implement these API's and getting and updating the details using the web.

Any help would be greatly appreciated.......

The-EDev commented 3 years ago

Well, you've got a long way to go, I would suggest reading the docs at https://crowcpp.org and maybe some file io guides. keep in mind you can read and write JSON within crow itself using crow::json::rvalue and crow::json::wvalue.

P.S. An API is the whole application you're trying to develop, the individual routes are called "endpoints", not "APIs"

sbenner commented 3 years ago

I don't think it's a correct place for the questions like that - a more appropriate would be the stackoverflow site and not the issue tracker in github

saivamsi98 commented 3 years ago

I don't think it's a correct place for the questions like that - a more appropriate would be the stackoverflow site and not the issue tracker in github

I posted in stackoverflow as well,but I didn't get any response there.

saivamsi98 commented 3 years ago

Well, you've got a long way to go, I would suggest reading the docs at https://crowcpp.org and maybe some file io guides. keep in mind you can read and write JSON within crow itself using crow::json::rvalue and crow::json::wvalue.

P.S. An API is the whole application you're trying to develop, the individual routes are called "endpoints", not "APIs"

can you help me with the code and explain about it? I would like to learn how it can be done. By seeing the examples I am not getting how crow really works and how to write.........

The-EDev commented 3 years ago

@saivamsi98 I can't really help you here, what you need is to learn general things about REST, the web, C++, etc.. Once you know these things you should be able to figure this stuff out yourself.

mrozigor commented 3 years ago

You should also read about reading/writing file in C++ (maybe with use of streams).

saivamsi98 commented 3 years ago

You should also read about reading/writing file in C++ (maybe with use of streams).

Yes, I'll do, thanks