Skip to content

Commit

Permalink
Merge pull request #17 from martin-olivier/version/2.2.0
Browse files Browse the repository at this point in the history
API Version 2.2.0
  • Loading branch information
dhbrojas authored Feb 5, 2022
2 parents 17aa6a9 + 03399f6 commit 7c4985b
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 199 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ find_package(googletest QUIET)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

Welcome to the **ZIAPI** repository which contains the interfaces and concrete implementations that make up our Epitech Zia project API proposal.

**ZIAPI** was elected as the city-wide API for the **Paris Region** in **2022**.
**ZIAPI** was elected as the city-wide API for the **Paris and Marseille Regions** in **2022**.

[**ZIAPI Official Website**](https://ziapi.vercel.app)
[**ZIAPI Official Discord**](https://discord.gg/ztptguX2sE)
[**ZIAPI Official Discord**](https://discord.gg/CzKv6dGXmf)

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/DIRECTORY_LISTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public:
[[nodiscard]] bool ShouldHandle(const ziapi::http::Context &ctx, const ziapi::http::Request &req) const override
{
/// We only want to handle GET requests.
return req.method == ziapi::http::method::GET;
return req.method == ziapi::http::method::kGet;
}

void Handle(ziapi::http::Context &ctx, const ziapi::http::Request &req, ziapi::http::Response &res) override {}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/REDIRECTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Let's now implement the `Handle()` method. We simply redirect each request to th

void Handle(http::Context &, const http::Request &, http::Response &res)
{
res.fields[ziapi::http::header::LOCATION] = redirection_route_;
res.status_code = ziapi::http::code::MOVED_PERMANENTLY;
res.fields[ziapi::http::header::kLocation] = redirection_route_;
res.status_code = ziapi::http::code::kMovedPermanently;
}

...
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/IMPLEMENT_HANDLER.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Then, let's implement the `ShouldHandle()`. This method is invoked to know if ou
```c++
[[nodiscard]] bool MyHandler::ShouldHandle(const http::Context &ctx, const http::Request &req) const
{
return req.method == http::method::GET;
return req.method == http::method::kGet;
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/IMPLEMENT_PREPROCESSOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Then, let's implement the `ShouldPreProcess()`. This method is invoked to know i
```c++
[[nodiscard]] bool ShouldPreProcess(const http::Context &ctx, const http::Request &req) const
{
return req.method == http::method::GET;
return req.method == http::method::kGet;
}
```
Expand All @@ -61,7 +61,7 @@ Great! Now our pre-processor will be called on all GET requests! Now let's add t
```c++
void MyPreProcessor::PreProcess(http::Context &ctx, http::Request &req)
{
req.method = http::method::POST;
req.method = http::method::kPost;
}
```

Expand Down
6 changes: 3 additions & 3 deletions examples/modules/directory-listing/DirectoryListingModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DirectoryListingModule : public ziapi::IHandlerModule {
[[nodiscard]] bool ShouldHandle(const ziapi::http::Context &ctx, const ziapi::http::Request &req) const override
{
/// We only want to handle GET requests.
return req.method == ziapi::http::method::GET;
return req.method == ziapi::http::method::kGet;
}

void Handle(ziapi::http::Context &ctx, const ziapi::http::Request &req, ziapi::http::Response &res) override
Expand All @@ -60,8 +60,8 @@ class DirectoryListingModule : public ziapi::IHandlerModule {
res.body = ss.str();
return;
}
res.status_code = ziapi::http::code::NOT_FOUND;
res.reason = ziapi::http::reason::NOT_FOUND;
res.status_code = ziapi::http::Code::kNotFound;
res.reason = ziapi::http::reason::kNotFound;
}

private:
Expand Down
4 changes: 2 additions & 2 deletions examples/modules/redirection/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class RedirectionModule : public ziapi::IHandlerModule {
{
/// Now we just say that the resource was moved permenatly and we indicate the new
/// location with the redirection route.
res.fields[ziapi::http::header::LOCATION] = redirection_route_;
res.status_code = ziapi::http::code::MOVED_PERMANENTLY;
res.fields[ziapi::http::header::kLocation] = redirection_route_;
res.status_code = ziapi::http::Code::kMovedPermanently;
}

[[nodiscard]] bool ShouldHandle(const ziapi::http::Request &req)
Expand Down
18 changes: 12 additions & 6 deletions include/ziapi/Http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include <any>
#include <map>
#include <unordered_map>
#include <optional>
#include <string>
#include <unordered_map>

#include "HttpConstants.hpp"

Expand All @@ -14,7 +15,7 @@ namespace ziapi::http {
*/
struct Request {
/// For possible values of version checkout ziapi::http::version.
int version;
Version version;

/// For possible values of method checkout ziapi::http::method.
std::string method;
Expand All @@ -31,10 +32,10 @@ struct Request {
*/
struct Response {
/// For possible values of version checkout ziapi::http::version.
int version;
Version version;

/// For possible values of version checkout ziapi::http::code.
int status_code;
Code status_code;

/// For possible values of version checkout ziapi::http::reason.
std::string reason;
Expand All @@ -43,7 +44,12 @@ struct Response {

std::string body;

void Bootstrap(int status_code = code::OK, std::string reason = reason::OK, int version = version::V1_1);
void Bootstrap(Code status_code = Code::kOK, std::string reason = reason::kOK, Version version = Version::kV1_1)
{
this->status_code = status_code;
this->reason = reason;
this->version = version;
}
};

/**
Expand All @@ -59,7 +65,7 @@ class IResponseInputQueue {
public:
virtual ~IResponseInputQueue() = default;

virtual std::pair<Request, Context> Pop() = 0;
[[nodiscard]] virtual std::optional<std::pair<Response, Context>> Pop() = 0;

[[nodiscard]] virtual std::size_t Size() const noexcept = 0;
};
Expand Down
Loading

0 comments on commit 7c4985b

Please sign in to comment.