Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » Multi-UI REST applications with U++
Re: Multi-UI REST applications with U++ [message #45998 is a reply to message #45996] Fri, 12 February 2016 12:48 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
NilaT wrote on Fri, 12 February 2016 11:07
Hello and sorry for picking up this old Thread.
I just wanted to ask if there is a REST implementation in UPP already?
Because I searched here and this thread was the only "useful" info I found.

I need to program a webserver which uses REST communication and JSON.
For JSON I already found the Json class but for REST I'm not sure.

So, any information about this is very appreciated.
Thanks in advance.

PS: Or maybe lectus, have you done an implementation by yourself and want to share it?


There is nothing magical about REST. It is just regular HTTP server, easy to do without any special support. Skeleton code can look e.g. like this:

void RESTProcess(TcpSocket& r)
{
	HttpHeader hdr;
	if(hdr.Read(r)) {
		VectorMap<String, String> urlvar;

		String uri = hdr.GetURI();
		int q = uri.Find('?');
 		if(q >= 0) {
 			ParseUrlVars(urlvar, ~uri + q + 1);
 			uri.Trim(q);
 		}
		
 		String req, n;
		 q = uri.Find('/');
 		if(q >= 0) {
 			n = uri.Mid(q + 1);
 			req = Filter(n, CharFilterAlphaToLower);
 		}
		
		if(hdr.GetMethod() == "GET") {
			if(req == "order") {
			}
		}
		if(hdr.GetMethod() == "POST") {
			if(req == "order") {
			}
		}
		if(hdr.GetMethod() == "PUT") {
			if(req == "order") {
			}
		}
		if(hdr.GetMethod() == "DELETE") {
			if(req == "order") {
			}
		}
	}
	HttpResponse(r, false, 400, "INVALID REQUEST");
}


TcpSocket server;

void Server()
{
	for(;;) {
		TcpSocket socket;
		LOG("Waiting...");
		bool b = socket.Accept(server);
		if(b) RESTProcess(socket);
	}
}

CONSOLE_APP_MAIN
{
	if(!server.Listen(4000, 10)) {
		LOG("Cannot open server port for listening\r\n");
		return;
	}
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: which linux distro for a 8 Gb usb?
Next Topic: MT opens up whole new can of worms :)
Goto Forum:
  


Current Time: Sat Apr 20 02:20:37 CEST 2024

Total time taken to generate the page: 0.05786 seconds