0

I'm working on a project which is using C++ RESTAPI. Im follwing Casablanca tutorial. According to that tutorial I added Casablanca to my C++ console aplication project using NuGet package manager. I am using Visual Studio 2015 Enterprise Edition. I am getting errors when I try to build my solution that 'http': a namespace with this name does not exist


'web': a namespace with this name does not exist

'web': is not a class or namespace name

'http': a namespace with this name does not exist

'web': is not a class or namespace name

'client': a namespace with this name does not exist

'concurrency': is not a class or namespace name

'streams': a namespace with this name does not exist. enter image description here 'make_shared': is not a member of 'std'

enter code here
// RESTProject.cpp : Defines the entry point for the console application.
//
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <fstream>
#include <iostream>
#include "stdafx.h"

using namespace std;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;
using namespace std;

int main()
{
    auto filestream = std::make_shared<concurrency::streams::ostream>();
    pplx::task<void> requesttask =concurrency::streams::fstream::open_ostream(U("result.html")).then([=](concurrency::streams::ostream outfile)
    {
        *filestream = outfile;


        // Create http_client to send the request.
        http_client client(U("http://www.bing.com/"));

        // Build request URI and start the request.
        uri_builder builder(U("/search"));
        builder.append_query(U("q"), U("cpprestsdk github"));
        return client.request(methods::GET, builder.to_string());
    });
    return 0;
}

2 Answers2

0

I had to add stdio.h include to resolve the issue

0

Following to the documentation, installation via NuGet package is not recommended. For Windows, appropriate way is to install with using Vcpkg:

  • Clone the vcpkg repo from GitHub. Please keep in mind, that packages will require a lot of space (about 10Gb for CppRestSDK with its dependencies).
  • Run the bootstrapper in the root folder: "bootstrap-vcpkg.bat".
  • Run "vcpkg integrate install" with admin rights for configure Visual Studio to locate all vcpkg header files and binaries.
  • Install CppRestSDK via command "vcpkg install cpprestsdk cpprestsdk:x64-windows" (it can take about 1 hour).

After that, restart VS and try to create empty project and add some reference, for example:

#include <cpprest/http_client.h>

When you type the file path, should work auto-completion, and also you can open this file from context menu. Keep in mind, this may not work in existing projects, which were created in previous version of VS.

Pavel K.
  • 983
  • 9
  • 21