Giter VIP home page Giter VIP logo

aliakbarrashidi / qttpserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supamii/qttpserver

0.0 1.0 0.0 11.12 MB

Build your API with C++ - Powered by Qt and Node's libuv

Home Page: https://supamii.github.io/qttpserver/

License: MIT License

Python 6.47% Batchfile 0.01% QMake 0.28% C 1.54% C++ 50.12% CMake 0.38% Makefile 0.35% M4 0.35% Shell 0.36% CSS 5.74% HTML 0.08% JavaScript 34.32%

qttpserver's Introduction

Build Status

QttpServer 1.0.0

QttpServer focuses on developing a lean and mean C++ based API server. In addition to leveraging modern C++, QttpServer also employs Qt to promote productivity and reinforce best practices. Use it for systems that are resource constrained, general prototyping, integrate into existing Qt Applications, or if you simply wish to save a few bucks on your cloud servers.

Getting started is EASY! Just load qttpserver.pro into QtCreator!

Check out the examples and samples to get started with your RESTful API server!

QttpServer

Features

Example 1:

Using a raw std::function based callback

#include <httpserver.h>

int main(int argc, char** argv)
{
  QCoreApplication app(argc, argv);

  // Always initialize in the main thread.
  qttp::HttpServer* httpSvr = qttp::HttpServer::getInstance();
  httpSvr->initialize();

  // Create an action, named "sayHello", that will handle all requests
  auto action = httpSvr->createAction([](qttp::HttpData& data) {
    // Form the JSON content and let the framework handle the rest.
    QJsonObject& json = data.getResponse().getJson();
    json["hello"] = "world";
  });

  // Register the action to handle http GET for the path "/".
  action->registerRoute(qttp::HttpMethod::GET, "/");

  // Register the action to handle http GET for the path "/hello".
  action->registerRoute(qttp::HttpMethod::GET, "/hello");

  // Libuv runs in its own thread.
  httpSvr->startServer();

  // Qt takes the main thread per the usual.
  return app.exec();
}

Example 2:

Using the action interface

#include <httpserver.h>

using namespace qttp;

class SayGoodbye : public Action {
  public:
    void onAction(HttpData& data) {
      QJsonObject& json = data.getResponse().getJson();
      json["response"] = "adios";
    }
    const const char* getName() const { return "sayGoodbye"; }
};

int main(int argc, char** argv)
{
  QCoreApplication app(argc, argv);
  HttpServer* httpSvr = HttpServer::getInstance();
  httpSvr->initialize();
  
  // Adds the action interface via template method.
  auto action = httpSvr->createAction<SayGoodbye>();
  
  action->registerRoute({
    {qttp::HttpMethod::GET, "/bye"},
    {qttp::HttpMethod::POST, "/aloha"}
  });

  httpSvr->startServer();
  return app.exec();
}

SwaggerUI Integrated

SwaggerUIQttpServer Operations

Get Started NOW

Prerequisites

  1. git

  2. qt installer or build from source. Below I've successfully used this tarball.

    # Building from source is a breeze for Ubuntu SERVER 12 & 14 LTS
    sudo apt-get install libssl-dev
    wget http://download.qt.io/official_releases/qt/5.5/5.5.1/single/qt-everywhere-opensource-src-5.5.1.tar.gz
    tar -xvf qt-everywhere-opensource-src-5.5.1.tar.tz
    cd qt-everywhere-opensource-src-5.5.1
    ./configure -nomake examples -opensource -skip qtwebkit -skip qtwebchannel -skip qtquick1 -skip qtdeclarative -openssl-linked
    make
    sudo make install

Setup

git clone https://github.com/supamii/QttpServer.git
cd QttpServer

Git submodules/dependencies automatically pulls in mongodb-drivers, boost, libuv, http-parser

git submodule update --init

Using QtCreator, open qttpserver.pro and enjoy!

QttpServer project loaded in QtCreator

Using QMake:

qmake CONFIG+=debug qttpserver.pro
make

By default, qttpserver will compile as a static library for ease of use. Check out the examples here for a quick-start. If you run into any blockers, feel free to open bug(s) and ask questions!

More Resources

Building Redis and MongoDB

Checkout the guide.

Examples and Tutorials

Riiiight over... Here

Alternate Build Scripts

node.native was previously built using gyp - you can learn more about that here

Note: It's likely that these will get phased out.

Credits

QttpServer is a fork from node.native with some additional contributions from tojocky.

License

The MIT License (MIT)

Copyright (c) 2016 Son-Huy Pham

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

qttpserver's People

Contributors

supamii avatar d5 avatar tojocky avatar divanvisagie avatar dennycd avatar kennethho avatar atnesness avatar bluehaunter avatar stefanspieker avatar takano32 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.