SiddiqSoft.SplitUri 1.4.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SiddiqSoft.SplitUri --version 1.4.1                
NuGet\Install-Package SiddiqSoft.SplitUri -Version 1.4.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SiddiqSoft.SplitUri" Version="1.4.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SiddiqSoft.SplitUri --version 1.4.1                
#r "nuget: SiddiqSoft.SplitUri, 1.4.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SiddiqSoft.SplitUri as a Cake Addin
#addin nuget:?package=SiddiqSoft.SplitUri&version=1.4.1

// Install SiddiqSoft.SplitUri as a Cake Tool
#tool nuget:?package=SiddiqSoft.SplitUri&version=1.4.1                

SplitUri : Parse Uri Utility

Build Status Build Status alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Objective

Parse the Uri for HTTP resources with support for format and nlohmann.json.

While there are many, many libraries available, the goal of this implementation is to make usage easy along with a modern design.

Features

  • C++20 compliant toolchain: We use <concepts>, <format>.
  • The nlohmann.json library.
  • Support for std::string and std::wstring
  • The build and tests are for Visual Studio 2019 under x64.

Usage

Examples

#include "siddiqsoft/SplitUri.hpp"
..
..
using namespace siddiqsoft::literals;
// Use the literal operator helper.
auto uri= "https://www.google.com/search?q=siddiqsoft"_Uri;
// Outputs https://www.google.com/search?q=siddiqsoft
std::cout << std::format("{}", uri) << std::endl;

A more through example

using namespace siddiqsoft::literals;

auto u = "https://www.google.com/search?q=siddiqsoft#v1"_Uri;

EXPECT_EQ("www.google.com", u.authority.host);
std::cerr << u.authority.host << std::endl;

EXPECT_EQ(443, u.authority.port);
std::cerr << u.authority.port << std::endl;

EXPECT_EQ("/search?q=siddiqsoft#v1", u.urlPart);
std::cerr << u.urlPart << std::endl;

EXPECT_EQ("q=siddiqsoft", u.queryPart);
std::cerr << u.queryPart << std::endl;

EXPECT_EQ("v1", u.fragment);
std::cerr << u.fragment << std::endl;

EXPECT_EQ("search", u.path.at(0));
std::cerr << nlohmann::json(u.path).dump() << std::endl;

EXPECT_EQ("siddiqsoft", u.query.at("q"));
std::cerr << nlohmann::json(u.query).dump() << std::endl;

// Checks that both serializers are available (caught at compile-time)
EXPECT_EQ(siddiqsoft::UriScheme::WebHttps, u.scheme);
std::cerr << std::format("{}", u.scheme) << "...." << nlohmann::json(u.scheme).dump() << std::endl;

// Note that despite the initial uri string skipping the port, the SplitUri decodes and stores the port
EXPECT_EQ("www.google.com:443", std::format("{}", u.authority));
std::cerr << std::format("{}", u.authority) << std::endl;

// The "rebuilt" endpoint
EXPECT_EQ("https://www.google.com/search?q=siddiqsoft#v1", std::format("{}", u));
std::cerr << std::format("{}", u) << std::endl;

And the corresponding output

www.google.com
443
/search?q=siddiqsoft#v1
q=siddiqsoft
v1
["search"]
{"q":"siddiqsoft"}
https...."https"
www.google.com:443
https://www.google.com/search?q=siddiqsoft#v1

<hr/>

From Wikipedia we have the following structure of Uri.

		  userinfo       host      port
		  ┌──┴───┐ ┌──────┴──────┐ ┌┴┐
  https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top
  └─┬─┘   └───────────┬──────────────┘└───────┬───────┘ └───────────┬─────────────┘ └┬┘
  scheme          authority                  path                 query           fragment

API

Current implementation only supports the http and https scheme.

Uri
scheme UriScheme Enumeration of the Uri schemes. We currently only support http scheme.
authority Auth template argument defaulting to AuthorityHttp
path vector<> Array of strings each containing the path element
query map<> Map of query elements
url string Short-cut of the path, query and fragment section
template <class T = std::string, class Auth = AuthorityHttp<T>>
requires (std::same_as<std::string, T> || std::same_as<std::wstring, T>) && std::same_as<AuthorityHttp<T>, Auth>
struct Uri
{
    UriScheme  scheme;
    Auth       authority;
    vector<T>  path {};
    map<T, T>  query {};
    T          url {}; // contains the "balance" post Authority section

    operator T();

    NLOHMANN_DEFINE_TYPE_INTRUSIVE(Uri<T>, scheme, authority, url, path, query, fragment);
};

SplitUri()

template <class T = std::string, class Auth = AuthorityHttp<T>>
requires std::same_as<std::string, T> || std::same_as<std::wstring, T>
Uri<T, Auth> static SplitUri(const T& aEndpoint);

<hr/>

Roadmap

  • Update to handle std::wstring.
  • Support the other URI schemes.

<p align="right"> © 2021 Siddiq Software LLC. All rights reserved. </p>

Product Compatible and additional computed target framework versions.
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SiddiqSoft.SplitUri:

Package Downloads
SiddiqSoft.restcl

Focussed REST Client for modern C++

SiddiqSoft.CosmosClient

Azure Cosmos REST-API Client for Modern C++

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 136 10/26/2024
1.9.0-rc0002 64 10/26/2024
1.8.5 71 10/26/2024
1.8.4 532 6/1/2022
1.8.3 631 11/20/2021
1.8.2 418 9/8/2021
1.8.1 319 9/8/2021
1.8.0 20,984 9/8/2021
1.7.0 9,005 8/29/2021
1.6.5 299 8/28/2021
1.6.4 492 8/18/2021
1.6.3 335 8/18/2021
1.6.2 355 8/16/2021
1.6.1 504 8/16/2021
1.5.1 320 8/13/2021
1.5.0 1,084 8/13/2021
1.4.1 318 8/9/2021
1.4.0 755 8/9/2021
1.3.0 308 8/6/2021
1.2.0 365 8/5/2021
1.1.0 370 8/5/2021
1.0.1 1,998 8/3/2021