Files
cpp-httplib/docs-src/pages/ja/tour/01-getting-started.md
yhirose 797758a742 Documentation Site on GitHub Pages (#2376)
* Add initial documentations

* Update documentation for Basic Client and add WebSocket section

* feat: add a static site generator with multi-language support

- Introduced a new Rust-based static site generator in the `docs-gen` directory.
- Implemented core functionality for building sites from markdown files, including:
  - Configuration loading from `config.toml`.
  - Markdown rendering with frontmatter support.
  - Navigation generation based on page structure.
  - Static file copying and output directory management.
- Added templates for base layout, pages, and portal.
- Created a CSS file for styling and a JavaScript file for interactive features like language selection and theme toggling.
- Updated documentation source with new configuration and example pages in English and Japanese.
- Added a `justfile` target for building the documentation site.

* Add language/theme toggle functionality

- Created a new Japanese tour index page at docs/ja/tour/index.html
- Implemented navigation links for various sections of the cpp-httplib tutorial
- Added a language selector to switch between English and Japanese
- Introduced theme toggle functionality to switch between light and dark modes
- Added mobile sidebar toggle for better navigation on smaller screens
2026-02-28 14:45:40 -05:00

2.5 KiB
Raw Blame History

title, order
title order
Getting Started 1

cpp-httplibを始めるのに必要なのは、httplib.hとC++コンパイラーだけです。ファイルをダウンロードして、Hello Worldサーバーを動かすところまでやってみましょう。

httplib.h の入手

GitHubから直接ダウンロードできます。常に最新版を使ってください。

curl -LO https://github.com/yhirose/cpp-httplib/raw/refs/tags/latest/httplib.h

ダウンロードした httplib.h をプロジェクトのディレクトリに置けば、準備完了です。

コンパイラーの準備

OS 開発環境 セットアップ
macOS Apple Clang Xcode Command Line Tools (xcode-select --install)
Ubuntu clang++ または g++ apt install clang または apt install g++
Windows MSVC Visual Studio 2022 以降C++ コンポーネントを含めてインストール)

Hello World サーバー

次のコードを server.cpp として保存しましょう。

#include "httplib.h"

int main() {
    httplib::Server svr;

    svr.Get("/", [](const httplib::Request&, httplib::Response& res) {
        res.set_content("Hello, World!", "text/plain");
    });

    svr.listen("0.0.0.0", 8080);
}

たった数行で、HTTPリクエストに応答するサーバーが書けます。

コンパイルと実行

このチュートリアルのサンプルコードは、コードを簡潔に書けるC++17で書いています。cpp-httplib自体はC++11でもコンパイルできます。

# macOS
clang++ -std=c++17 -o server server.cpp

# Linux
# `-pthread`: cpp-httplibは内部でスレッドを使用
clang++ -std=c++17 -pthread -o server server.cpp

# Windows (Developer Command Prompt)
# `/EHsc`: C++例外処理を有効化
cl /EHsc /std:c++17 server.cpp

コンパイルできたら実行します。

# macOS / Linux
./server

# Windows
server.exe

ブラウザで http://localhost:8080 を開いてください。"Hello, World!" と表示されれば成功です。

curl でも確認できます。

curl http://localhost:8080/
# Hello, World!

サーバーを停止するには、ターミナルで Ctrl+C を押します。

次のステップ

サーバーの基本がわかりましたね。次は、クライアント側を見てみましょう。cpp-httplibはHTTPクライアント機能も備えています。

次: Basic Client