robiwano / siesta Goto Github PK
View Code? Open in Web Editor NEWC++ HTTP/REST/Websocket framework based on Nanomsg NG.
License: MIT License
C++ HTTP/REST/Websocket framework based on Nanomsg NG.
License: MIT License
Hi,
I have done some small bug fix/changes in order to compile with clang on macOS(ARM) but I cannot branch and pull any request. How can I contribute to this project?
I am attempting to create a basic REST API server using Siesta. However, I encountered an issue while trying to enable support for CORS on PUT requests. The browser initiates a preflight request in the form of an OPTIONS request, resulting in an "error 405 Method Not Allowed." Consequently, CORS verification fails.
I have inspected the code at common.h couldn't find explicit support for OPTIONS requests. Is there a way to enable them?
If there is no direct support, are there any workarounds that could address this issue?
Your assistance is greatly appreciated. Thanks in advance!
Say I have
holder += httpServer->addRoute(HttpMethod::GET, "/a/:b/:c", foo);
holder += httpServer->addRoute(HttpMethod::GET, "/a", bar);
The above code will work with URI like "/a/bb/cc" being directed to the function foo and "/a" to bar.
However if I switch the order around
holder += httpServer->addRoute(HttpMethod::GET, "/a", bar);
holder += httpServer->addRoute(HttpMethod::GET, "/a/:b/:c", foo);
"/a/bb/cc" can no longer be directed to the correct function.
How to reproduce:
#include <siesta/server.h>
using namespace siesta;
#include <chrono>
#include <iostream>
#include <sstream>
#include <thread>
#include "ctrl_c_handler.h"
void foo(const server::rest::Request& req, server::rest::Response& resp)
{
std::cout << "This is foo\n" << std::endl;
}
void bar(const server::rest::Request& req, server::rest::Response& resp)
{
std::cout << "This is bar\n" << std::endl;
}
int main(int argc, char** argv)
{
ctrlc::set_signal_handler();
try {
bool rest_shutdown = false;
std::string addr = "http://127.0.0.1:8090";
if (argc > 1) {
addr = argv[1];
}
auto server = server::createServer(addr);
server->start();
std::cout << "Server started, listening on port " << server->port()
<< std::endl;
server::TokenHolder h;
h += server->addRoute(HttpMethod::GET, "/a", bar);
h += server->addRoute(HttpMethod::GET, "/a/:b/:c", foo);
while (!ctrlc::signalled() && !rest_shutdown) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::cout << "Server stopped!" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return -1;
}
return 0;
}
Hi @robiwano ,
Hope you are all well !
I was wondering if it is complicated to extend siesta with the surveyor pattern and replicate what is described in this blog post https://daniel-j-h.github.io/post/distributed-search-nanomsg-bond/ ?
The idea would be to configure rest routes binding several, probably dockerized, respondent clients and aggregate all responses into one. Maybe, using a yaml file to configure the distribution tree ?!
Do you think it is doable ?
Thanks for your inputs and insights on that.
Cheers,
X
THX for you open source lib 'siesta'. I want to create a websocket server use nng, but I have no idea about how to create it until i found your repo. I read the source code and notice that you use nng_stream to solve it. Maybe there is a question when receive data. The repo use 'nng_stream_recv' to receive websocket data, but nng docs said that 'The I/O operation completes as soon as at least one byte has been received, or an error has occurred'. So it can't ensure that i receive whole data in a request?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.