我正在开发嵌入式Linux,我希望Restful web服务能够在我的Linux自定义板上运行。
我的目标是向web服务器(httpd server)发送/接收数据( JSON格式)。
另外,我希望使用C++语言创建Restful服务。
请参阅下面关于我的Linux自定义板需要Restful服务的想法。
有人有关于如何使用C++语言创建的想法或示例吗?
任何关于Restful的帮助都是受欢迎的。
有没有人想过ffead及其能满足我Restful的功能?
发布于 2018-06-06 04:31:14
发布于 2020-05-13 18:51:09
我正在结合使用燕麦和nlohmann JSON。尽管您可以使用纯oatpp,因为它已经内置了JSON处理特性。请看分步导轨。
发布于 2016-08-16 13:40:54
如果您使用Apache2或Nginx作为Web服务器,并希望在其上部署RESTful JSON服务,请尝试恩格列斯特。使用方便,速度快。
要在C++中表示JSON,ngrest使用标准C++类型 (泛型类型、C++结构、类型防御、STL容器等)。访问原始JSON也是可能的。可以选择使用ngrest-db扩展访问DBMS。
创建C++服务的典型工作流示例:
1)创建一个服务(它可以实现为h/cpp或单个hpp文件):
ngrest create -d hpp Users2)实现数据结构和操作(资源)。这样编辑users/users/src/Users.hpp:
// a structure to represent data in JSON
struct User {
int id;
std::string name;
std::string email;
};
// *location: /users
class Users: public ngrest::Service
{
public:
// *method: POST
int add(const User& user) {
return Db::inst().users().insert(user).lastInsertId();
}
// *location: /{id}
User get(int id) {
return Db::inst().users().selectOne("id = ?", id);
}
// *method: DELETE
void remove(int id) {
Db::inst().users().deleteWhere("id = ?", id);
}
};3)为测试运行您的服务:
cd users
ngrest4)使用服务测试器( RESTful http://localhost:9098/ngrest/service/users )测试您的Web服务
5)将Web服务库部署到运行ngrest的Web服务器上。
https://stackoverflow.com/questions/25057819
复制相似问题