Routes

Content

The following API routes are available under the content prefix. These routes are cached with public headers and a max age of 3600 seconds (1 hour).

The following API routes are available under the content prefix. These routes are cached with public headers and a max age of 3600 seconds (1 hour).

List of API end-points prefix content

  1. GET: /content/_ping
  2. GET: /content/menus
  3. GET: /content/menus/{slug}
  4. GET: /content/pages/{slug}
  5. GET: /content/posts/{slug}
  6. GET: /content/categories/{slug}/posts
  7. GET: /content/archives/{slug}
  8. POST: /content/pages-meta/{slug}
  9. GET: redirects
  10. GET: /brands

Middleware

  • Cache Headers: All routes under this prefix have caching headers set to public with a max_age of 3600 seconds.

Routes Prefix /content

1.Health Check

  • GET /content/_ping
    • Controller: PingController
    • Description: Checks if the API is alive and responsive.
    • Request:
      • Method: GET
      • URL: /content/_ping
      • Parameters: None
    • Response:
      {
      data:
      {
        "status": "ok"
      }
      }
      

2. GET: ../menus

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace, and it uses the ContentService to fetch menu items.
  • Service Dependencies: Uses ContentService to retrieve all menu items.
  • Resource Response: Returns a collection of all menu items
  • Description: Retrieves all menu items.
  • Request:
    • Method: GET
    • URL: /content/menus
    • Parameters: None
  • Example Response:
    • Status: 200 OK
    • Response:
      {
        "data": {
          "footer-company-information-en": [
            { "title": "About Us" },
            { "link": "/content/aboutus" }
          ],
            ...................
            ...................
            ...................
        }
      }
      
  • Error Response:
    • Status: 401 Unauthorized
      • Reason: Authentication token is missing or invalid.
      {
        "error": "Failed to retrieve menu items"
      }
      

3. GET: ../menus/{slug}

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and utilizes ContentService.
  • Service Dependencies: Uses ContentService to retrieve a menu item by its slug.
  • Authorization: Assumes user is authenticated; specific permissions are not enforced
  • Resource Response: Returns a single menu item based on the provided slug.
  • Description: Retrieve a menu item by its slug.
  • Request:
    • Method: GET
    • URL: /content/menus/{slug}
    • Parameters:
      • slug (string): The slug of the menu item.
  • Positive Response:
    • Status: 200 OK
    • Response:
       Example GET -> https://base_url/ecom/v1/content/menus/footer
      {
        "data": {
          "ID": x,
          "name": "footer-nl",
          "slug": "footer-nl",
          "description": "",
          "count": 27,
             "items": [
              {
                  "id": x,
                  "order": 1,
                  "parent": 0,
                  "title": "Customer service",
                  "url": "https://wordpress.gke.pre-prod.nl.toolstation.dev/toolstation?lang=nl",
                  "attr": "",
                     "childrens": [........],
                ],
      }
      }
      
  • Error Response:
  • Status: 404 Not Found
    • Reason: The menu item with the specified slug does not exist.
      {
        "error": "Menu item not found"
      }
      

4. GET: ../pages/{slug}

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and utilizes ContentService.
  • Service Dependencies ContentService to retrieve a page by its slug.
  • Authorization: Assumes user is authenticated; specific permissions are not enforced
  • Resource Response: Returns a single page's details based on the slug.
  • Description: Retrieve a page by its slug.
  • Request:
    • Method: GET
    • URL: /content/pages/{slug}
    • Parameters:
      • slug (string): The slug of the page.
  • Response:
    • Status: 200 OK
    • Response:
       Example GET->https://base_url/ecom/v1/content/pages/terms
      {
         "data": [
          {
             "id": x,
              "date": "2020-12-21T09:55:33",
              "date_gmt": "2020-12-21T09:55:33",
              "guid": {
                  "rendered": "https://content.toolstation.nl/?p=17749"
              },
              "modified": "2020-12-21T09:55:33",
              "modified_gmt": "2020-12-21T09:55:33",
              "slug": "aangepaste-openings-en-levertijden",
              "status": "publish",
              "type": "post",
              "link": "https://wordpress.gke.pre-prod.nl.toolstation.dev/aangepaste-openings-en-levertijden",
              "title": {
                  "rendered": "Aangepaste openings- en levertijden"
              },
              "content": {...}
          },
          {
            "id": 2,
            .......,
      
          }
        ]
      }
      
  • Error Response:
  • Status: 404 Not Found
    • Reason: The page with the specified slug does not exist.
      {
        "error": "Page not found"
      }
      

5. POST: ../pages-meta/{slug}

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and imports necessary classes including FetchContentRequest, Response, and Log.
  • Service Dependencies ContentService to retrieve page meta data based on the slug and provided meta keys.
  • Authorization: Assumes user is authenticated; specific permissions are not enforced
  • Logging: Logs debug information including meta keys provided in the request.
  • Resource Response: Returns meta data for the page based on the slug and requested meta keys.
  • Description: Retrieve meta data for a page by its slug based on the provided meta keys.
    • Request:
      • Method: POST
      • URL: /content/pages-meta/{slug}
      • Parameters:
        • slug (Path Parameter): The slug of the page for which meta data is being requested.
        • meta_keys (Request Body): An array or comma-separated string of meta keys to retrieve.
      • Request Body:
        POST /content/pages-meta/example-page
        Authorization: Bearer {token}
        Content-Type: application/json
        {
          "meta_keys": ["description", "keywords"]
        }
        
  • Positive Response:
    • Status: 200 OK
    • Response:
       Example POST->https://base_url/ecom/v1/pages-meta/terms
      {
        "data": {
          "web_url": "/content/terms"
         },
      }
      
  • Error Response:
  • Status: 404 Not Found
    • Reason: The page with the specified slug does not exist or no meta data was found.
  • Status: 400 Bad Request
    • Reason: The request body is malformed or the keys parameter is missing or invalid.
    • Response:
      {
        "error": "Page meta information not found"
      }
      

FetchContentRequest Class

The FetchContentRequest class is used to handle and validate incoming requests for fetching content.

  • Key Methods:
    • authorize(): Determines if the user is authorized to make this request. Returns true, allowing all users to make the request.
    • rules(): Returns an empty array as no specific validation rules are applied to this request.
    • getMetaKeys() meta keys from the request. It handles the keys parameter, which can be an array or a comma-separated string.

getMetaKeys Method

  • Description: Extracts meta keys from the request input. If the keys parameter is a comma-separated string, it converts it into an array.
  • Usage: Used in the getPageMetaBySlug method to determine which meta keys to fetch for the page.

6. GET: ../posts/{slug}

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and utilizes ContentService.
  • Service Dependencies ContentService to retrieve a post by its slug.
  • Authorization: Assumes user is authenticated; specific permissions are not enforced
  • Resource Response: Returns a single post's details based on the slug.
  • Description: Retrieve a post by its slug.
  • Request:
    • Method: GET
    • URL: /content/posts/{slug}
    • Parameters:
      • slug (string): The slug of the post.
  • Example Request
GET /content/posts/example-post
Authorization: Bearer {token}

  • Positive Response:
    • Status: 200 OK
    • Response:
      {
        "data": {
          "id": 1,
          "title": "Post Title",
          "content": "Post content...",
          "author": "Author Name",
          "published_at": "2024-08-07T12:34:56Z",
               .........................,
               ..........................
        }
      }
      
  • Error Response:
  • Status: 404 Not Found
    • Reason: The post with the specified slug does not exist.
      {
        "error": "Post not found"
      }
      

7. GET: ../categories/{slug}/posts

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and utilizes ContentService.
  • Service Dependencies ContentService to retrieve posts by category slug.
  • Authorization: Assumes user is authenticated; specific permissions are not enforced.
  • Pagination: Supports pagination for the list of posts.
  • Resource Response: Returns a paginated list of posts in the specified category.
  • Description: Retrieves posts associated with a specific category slug.
  • Request:
    • Method: GET
    • URL: /content/categories/{slug}/posts
    • Parameters:
      • slug (string): The slug of the category.
  • Example Request
GET /content/categories/example-category/posts?page=1&pageLimit=10
Authorization: Bearer {token}
  • Response:
    • Status: 200 OK
    • Response:
      {
        "data": [
          {
              "id": xyz,
              "date": "2021-06-01T10:54:07",
              "date_gmt": "2021-06-01T10:54:07",
              "guid": {
                  "rendered": ""
              },
              "modified": "2021-06-02T11:03:19",
              "modified_gmt": "2021-06-02T11:03:19",
              "slug": "nieuw-nu-ook-in-rotterdam-noord-west",
              "status": "publish",
              "type": "post",
              "link": "",
              "title": {
                  "rendered": "Nieuw | Nu ook in Rotterdam Noord-West"
              },
              "content": {
                  "rendered": ,
                  "protected": false
              },
              "excerpt": {"protected": false},
              "author": 16,
              "featured_media": 19434,
              "comment_status": "open",
              "ping_status": "open",
              "sticky": false,
              "template": "",
              "format": "standard",
              "meta": {
                  "footnotes": ""
              },
              "categories": [],
              "tags": [],
              "acf": [],
              "post_thumbnail_url": ",
              "current_locale": {
                  "language_code": "en",
                  "locale": "en_US"
              },
              "translations": {
                  "nl": {
                      "locale": 
                      "id":
                      "post_title": 
                      "post_content": 
                      "meta": []
                  }
              },
              "_links": {
                  "self": [
                      {
                      }
                  ],
                  "collection": [
                      {
                      }
                  ],
                  "about": [
                      {
                      }
                  ],
                  "author": [
                      {
                          "embeddable": true,
                      }
                  ],
                  "replies": [
                      {
                          "embeddable": true,
                          "href":
                      }
                  ],
                  "version-history": [
                      {
                          "count": 0,
                          "href": 
                      }
                  ],
                  "wp:featuredmedia": [
                      {
                          "embeddable": true,
                          "href": 
                      }
                  ],
                  "wp:attachment": [
                      {
                          "href": 
                  ],
                  "wp:term": [
                      {
                          "taxonomy": "category",
                          "embeddable": true,
                          "href": ""
                      },
                      {
                          "taxonomy": "post_tag",
                          "embeddable": true,
                          "href": ""
                      }
                  ],
                  "curies": [
                      {
                          "name": "wp",
                          "href": "",
                          "templated": true
                      }
                  ]
              }
          },
        ]
      }
      
  • Error Response:
  • Status: 404 Not Found
    • Reason: The category with the specified slug does not exist.
    • Response:
      {
        "error": "No posts found for this category"
      }
      

8. GET:../archives/{slug}

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and utilizes ContentService.
  • Service Dependencies ContentService to retrieve archives by slug.
  • Authorization: Assumes user is authenticated; specific permissions are not enforced.
  • Pagination: Supports pagination for the list of posts.
  • Resource Response: Returns details of the archive based on the slug.
  • Description: Retrieves archive information by its slug.
  • Request:
    • Method: GET
    • URL: /content/archives/{slug}
    • Parameters:
      • slug (string): The slug of the archive.
  • Example Request
    GET /content/archives/example-archive
    Authorization: Bearer {token}
    
  • Response:
    • Status: 200 OK
    • Response:
       Example GET-> https://base_url/ecom/v1/content/archives/dec-2020
      {
        "data": [
          {
             "id": 17749,
              "date": "2020-12-21T09:55:33",
              "date_gmt": "2020-12-21T09:55:33",
              "guid": {
                  "rendered": "https://content.toolstation.nl/?p=17749"
              },
              "modified": "2020-12-21T09:55:33",
              "modified_gmt": "2020-12-21T09:55:33",
              "slug": "aangepaste-openings-en-levertijden",
              "status": "publish",
              "type": "post",
              "link": "https://wordpress.gke.pre-prod.nl.toolstation.dev/aangepaste-openings-en-levertijden",
              "title": {
                  "rendered": "Aangepaste openings- en levertijden"
              },
              "content": {...}
          },
          {
            "id": 2,
            .......,
      
          }
        ]
      }
      
  • Error Response:
  • Status: 404 Not Found
    • Reason: The archive with the specified slug does not exist.
      {
        "error": "Resource Not Found"
      }
      
  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and utilizes ContentService.
  • Service Dependencies ContentServiceto retrieve archive links.
  • Authorization: Assumes user is authenticated; specific permissions are not enforced.
  • Pagination: Supports pagination for the list of posts.
  • Resource Response: Returns a list of archive links.
  • Description: Retrieves a list of archive links.
  • Request:
    • Method: GET
    • URL: /content/archive-links
    • Parameters: None
  • Example Request
    GET /content/archive-links
    Authorization: Bearer {token}
    
  • Response:
    • Status: 200 OK
    • Response:
      {
        "data": [
          {
              
              .......................
          },
          {
             ....................
          }
      ]
      }
      
  • Error Response:
  • Status: 401 Unauthorized
    • Reason: Authentication token is missing or invalid.
      {
        "error": "Resource Not Found"
      }
      

10. GET: redirects

Overview

The RedirectController provides an API endpoint that serves a list of redirects. It utilizes caching to avoid hitting the database on every request, thereby improving performance. The RedirectResource is used to format the redirect data into a consistent JSON structure.

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace. It imports necessary classes and interfaces including RedirectResource, Request, Cache, and Redirect.
  • Service Dependencies the Redirect model to retrieve redirect data and RedirectResource to format the response.
  • Caching the redirect data using Laravel's cache system to improve performance and reduce database queries.
  • Content-Type: Ensures the response is returned as JSON with a Content-Type header set to application/json.
  • Description: Fetches a list of active redirects from the database, caches the result, and returns it as JSON.
  • __invoke Method:
    Handles the retrieval of redirects and returns them as a JSON response.
  • Request:
    • Method: GET
    • URL: /redirects
    • Parameters: None
    • Headers:
      • Authorization: required, depending on authentication requirements.
  • Example Request
    GET /redirects
    Authorization: Bearer {token}  // required
    
  • Response:
    • Status: 200 OK
    • Response:
      {
      "data": [
          {
              "from": "/old-page",
              "to": "/new-page",
              "preserve_query_string": true
          },
          {
              "from": "/another-old-page",
              "to": "/another-new-page",
              "preserve_query_string": false
          }
        ]
      }
      
  • Example Usage: The RedirectResource is used in the RedirectController to format the data for the /redirects endpoint.
  • Example Transformation: Given a Redirect model instance with the following properties:
    • from = /old-page
    • to = /new-page
    • preserveQueryString = true
  • Error Response:
  • Status: 500 Internal Server Error
    • Reason: This status may be returned if there is an issue with retrieving the redirects from the database or handling the cache.

11. GET: /brands

  • Namespace and Imports: The controller is part of the App\Http\Controllers\Api namespace and imports necessary classes including Cache, Response, and BrandService.
  • Service Dependencies BrandService to retrieve a list of visible brands.
  • Caching the brand data using Laravel's caching system to enhance performance and reduce database queries.
  • Content-Type: Ensures the response is returned as JSON with a Content-Type header set to application/json.
  • __invoke Method:
    Handles the retrieval of brands and returns them as a JSON response.
  • Request:
    • Method: GET
    • URL: /brands
    • Parameters: None
    • Headers:
      • Authorization: Optional, depending on authentication requirements.
  • Example Request
    GET https://base_url/ecom/v1/content/brands
    Authorization: Bearer {token}  // Required
    
  • Response:
    • Status: 200 OK
    • Response:
      Example-> https://base_url/ecom/v1/content/brands
      {
      "data": {
          "3M": "3m",
          "ABA": "aba",
          "ABB": "abb",
          "ABC-ADAMAS": "abc-adamas",
          "ACO": "aco",
           ..........
      }
      }
      
  • Caching Details:
    • Cache Key: 'website.content.brands'
    • TTL (Time To Live): Defined by the content.brands_cache_ttl configuration value.
    • Fallback cache is not available, the BrandService is queried to fetch the brands.
  • Error Response:
  • Status: 500 Internal Server Error
    • Reason: This status may be returned if there is an issue with retrieving the brands from the service or handling the cache.

Summary

The negative responses across these methods are generally 404 Not Found, with a brief error message to indicate the type of issue encountered. This approach helps clients identify and handle errors more effectively.


Copyright © 2026