Giter Site home page Giter Site logo

meenapintu / restweb Goto Github PK

View Code? Open in Web Editor NEW
74.0 9.0 32.0 1.68 MB

Sample code of cpprestsdk (casablanca), it's a sample example for beginner to get started with cpprestsdk with database(currently PostgreSQL) integration with basic structure, programmer can extend it.

License: MIT License

CMake 13.61% C++ 74.78% HTML 11.61%
cpprestsdk casablanca sample c-plus-plus postgresql-database postgresql-driver restful cmake dbms libpq

restweb's People

Contributors

meenapintu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

restweb's Issues

initial run fails with exception.

I'm newbie in rest and web services, and possibly I'm doing something wrong, please clarify.
I've just built the project successfully (WSL, Ubuntu 16.04).
and ran this. when I'm trying to request to this from browser (just opening localhost:) it raise the exception here:
`
void handler::handle_get(http_request message)

{
// ...
concurrency::streams::fstream::open_istream(U("static/index.html"), std::ios::in).then([=](concurrency::streams::istream is)
{
message.reply(status_codes::OK, is, U("text/html"));
});

//...

in pplxtasks.h
// If you are trapped here, it means an exception thrown in task chain didn't get handled.
// Please add task-based continuation to handle all exceptions coming from tasks.
// this->_M_stackTrace keeps the creation callstack of the task generates this exception.
_REPORT_PPLTASK_UNOBSERVED_EXCEPTION();
`

have any idea why this can be there?

Missing #include <cpprest/filestream.h>

handler.cpp is missing a required header.

#include <cpprest/filestream.h>

It would be nice if the headers that are used are there for the .cpp files and not bundled into headers. This makes reuse a lot easier and improves readability. It would also be nice if there was a solution file so people who use Microsoft can compile the project.

Using the REST server in LAN

Hi i'm quite new to programming, and need some help. I am able to get the server and example RestWeb server up and running, and it works fine in localhost (http://localhost:34568/). But when i try to use another computer to access via IP address (http://(IP address):34568/) using LAN it does not work. i tested it locally again via IP address and it also doesn't work. anyone has any solution?

I'm setting up the cpprestsdk in Raspberry Pi 2, Ubuntu Mate 16.04. I'm trying to use the SDK to build a REST API service.

BTW, i noticed that the MAKE process for installing the RestWeb server will have errors, but can be resolved by adding -lpthread in the CMakeLists.txt

build in macOS failed: ld: library not found for -lcrypto

Describe the bug
when compile it in mac with mac branch, after making the project, the making progress reached 100%, but it still report an error: ld: library not found for -lcrypto.

crypto

To Reproduce
Steps to reproduce the behavior:

  1. cmake . (in mac branch, install cpprestsdk with brew)
  2. make
  3. failed..

before I installed openssl to the /usr/local/lib, make failed when progress reached 33%, because openssl installed in another non-standard path. after I install openssl to /usr/local/lib, the make could reach 100%, but it still report the same error, this annoyed me ๐Ÿ˜ข

Expected behavior
make successfully.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS 10.15
  • CMake 3.14.3
  • clang 11.0.0

Additional context
building it successfully in windows and ubuntu.

unicode under win platform

C:\dev\workspace\Restweb\src\handler.cpp(91): error C2440: 'initializing': cannot convert from 'const wchar_t [32]' to 'std::basic_string<char,std::char_traits,std::allocator>'

from my perspective , it happens because you are using unicode strings under windows however I don't see any flags in cmakelists to specify this.

I suppose you build this in visual studio which sets _UNICODE by default? have you tried to build the project using cmake only? without IDE?

undefined reference to symbol 'pthread_cond_clockwait@@GLIBC_2.30'

I faced the following error during build on Linux:

/usr/bin/ld: CMakeFiles/restserver.dir/main.cpp.o: undefined reference to symbol 'pthread_cond_clockwait@@GLIBC_2.30'
/usr/bin/ld: /usr/lib/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Environment:
gcc 10.2.0
cmake 3.19.5
Arch Linux: 5.10.16-arch1-1

Solution:
POSIX threads need to be linked.

When building on mac, ld: library not found for -lcrypto

I was trying to build on mac I see errors.
ravi-mac:Restweb ravi.gupta$ cmake .
-- Boost version: 1.67.0
-- Found the following Boost libraries:
-- random
-- system
-- thread
-- filesystem
-- chrono
-- atomic
-- date_time
-- regex
-- Boost_INCLUDE_DIRS: /usr/local/include
-- Boost_LIBRARIES: /usr/local/lib/libboost_random-mt.dylib;/usr/local/lib/libboost_system-mt.dylib;/usr/local/lib/libboost_thread-mt.dylib;/usr/local/lib/libboost_filesystem-mt.dylib;/usr/local/lib/libboost_chrono-mt.dylib;/usr/local/lib/libboost_atomic-mt.dylib;/usr/local/lib/libboost_date_time-mt.dylib;/usr/local/lib/libboost_regex-mt.dylib
-- Boost_VERSION: 106700
-- OPENSSL_INCLUDE_DIRS: /usr/local/opt/openssl/include
-- OPENSSL_LIBRARIES: /usr/local/opt/openssl/lib/libssl.dylib;/usr/local/opt/openssl/lib/libcrypto.dylib
-- OPENSSL_VERSION: 1.0.2p
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ravi.gupta/learning/solver-app/others/Restweb

ravi-mac:Restweb ravi.gupta$ make
[ 33%] Building CXX object CMakeFiles/restserver.dir/main.cpp.o
[ 66%] Building CXX object CMakeFiles/restserver.dir/src/handler.cpp.o
[100%] Linking CXX executable Build/bin/restserver
ld: library not found for -lcrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Build/bin/restserver] Error 1
make[1]: *** [CMakeFiles/restserver.dir/all] Error 2
make: *** [all] Error 2

cmake configuration

this is a feature request, not a bug.
is it possible for you to extend cmakelists with
ExternalProject_Add statement for auto-cloning and build casablanca prior of your project build will be started?

P.S. could you also add a requirements into readme ? my compiler could not find pqxx headers.
if you'd add "PostgreSQL required" , it would be clear for a starting

Different URLs call different get requests

Is your feature request related to a problem? Please describe.
Thank you very much for your project, it helps me a lot since I'm a green hander for C++. According to your demo, I could easily create a server which has 4 different requests, and we visit them through the same url http://localhost:34568 with different request types(GET, POST ..).

But if I want to create another GET request like http://localhost:34568/rest/api, I have no idea how to do it.

Describe the solution you'd like
if you don't mind, please add an example code in this project.

Additional context
what I want to do is that: when visit http://localhost:34568/first, then excute handle_get1, and when visit http://localhost:34568/second, then excute handle_get2.
handler.cpp

// visit it by url "http://localhost:34568/first"
void handler::handle_get1(http_request message) {
  // do some things
}

// visit it by url "http://localhost:34568/seconde"
void handler::handle_get2(http_request message) {
  // do other things
}

global error handler for http_listener

hi, there's handler::handle_error, but i don't see where it's used.

is there way to set global error handler, so i dont need to try/catch all handlers to log exceptions? otherwise looks like http_listener just swallows exception and replies with 500.

Will not build in vs2017

I cannot get this project to build in vs2017, even using the vsc15_v140 branch. It says there are missing packages from NuGet that are required to install. Should this really require NuGet? I installed CppRestSDK with vcpkg. The cpprestsdk github page advises against using Nuget. I don't see any references to any other libraries in the source code other than cpprest, why wouldn't it work with cpprestsdk installed with vcpkg?

fatal error: cpprest/json.h: No such file or directory

ERROR ->

eduardo@suse:/Private/casablanca/Restweb> make
[ 33%] Building CXX object CMakeFiles/restserver.dir/main.cpp.o
In file included from /home/eduardo/Private/casablanca/Restweb/main.cpp:3:0:
/home/eduardo/Private/casablanca/Restweb/include/stdafx.h:21:26: fatal error: cpprest/json.h: No such file or directory
#include "cpprest/json.h"
^
eduardo@suse:
/Private/casablanca/Restweb> tree -L 2
.
โ”œโ”€โ”€ Build
โ”‚ย ย  โ””โ”€โ”€ bin
โ”œโ”€โ”€ CMakeCache.txt
โ”œโ”€โ”€ CMakeFiles
โ”‚ย ย  โ”œโ”€โ”€ 3.5.2
โ”‚ย ย  โ”œโ”€โ”€ cmake.check_cache
โ”‚ย ย  โ”œโ”€โ”€ CMakeDirectoryInformation.cmake
โ”‚ย ย  โ”œโ”€โ”€ CMakeOutput.log
โ”‚ย ย  โ”œโ”€โ”€ CMakeTmp
โ”‚ย ย  โ”œโ”€โ”€ feature_tests.bin
โ”‚ย ย  โ”œโ”€โ”€ feature_tests.c
โ”‚ย ย  โ”œโ”€โ”€ feature_tests.cxx
โ”‚ย ย  โ”œโ”€โ”€ Makefile2
โ”‚ย ย  โ”œโ”€โ”€ Makefile.cmake
โ”‚ย ย  โ”œโ”€โ”€ Progress
โ”‚ย ย  โ”œโ”€โ”€ progress.marks
โ”‚ย ย  โ”œโ”€โ”€ restserver.dir
โ”‚ย ย  โ””โ”€โ”€ TargetDirectories.txt
โ”œโ”€โ”€ cmake_install.cmake
โ”œโ”€โ”€ CMakeLists.txt
โ”œโ”€โ”€ dbms
โ”‚ย ย  โ”œโ”€โ”€ CMakeLists.txt
โ”‚ย ย  โ”œโ”€โ”€ dbms
โ”‚ย ย  โ”œโ”€โ”€ dbms.cbp
โ”‚ย ย  โ”œโ”€โ”€ dbms.layout
โ”‚ย ย  โ”œโ”€โ”€ default.sql
โ”‚ย ย  โ”œโ”€โ”€ include
โ”‚ย ย  โ”œโ”€โ”€ main.cpp
โ”‚ย ย  โ”œโ”€โ”€ readme.md
โ”‚ย ย  โ””โ”€โ”€ src
โ”œโ”€โ”€ include
โ”‚ย ย  โ”œโ”€โ”€ handler.h
โ”‚ย ย  โ””โ”€โ”€ stdafx.h
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ main.cpp
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ src
โ”‚ย ย  โ””โ”€โ”€ handler.cpp
โ””โ”€โ”€ static
โ”œโ”€โ”€ index.html
โ””โ”€โ”€ index.html.save-failed

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.