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
- GET:
/content/_ping - GET:
/content/menus - GET:
/content/menus/{slug} - GET:
/content/pages/{slug} - GET:
/content/posts/{slug} - GET:
/content/categories/{slug}/posts - GET:
/content/archives/{slug} - POST:
/content/pages-meta/{slug} - GET:
redirects - GET:
/brands
Middleware
- Cache Headers: All routes under this prefix have caching headers set to
publicwith amax_ageof 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
- Method:
- Response:
{ data: { "status": "ok" } }
- Controller:
2. GET: ../menus
- Namespace and Imports: The controller is part of the
App\Http\Controllers\Apinamespace, and it uses theContentServiceto fetch menu items. - Service Dependencies: Uses
ContentServiceto retrieve all menu items. - Resource Response: Returns a
collectionof all menu items - Description: Retrieves all menu items.
- Request:
- Method:
GET - URL:
/content/menus - Parameters: None
- Method:
- Example Response:
- Status:
200 OK - Response:
{ "data": { "footer-company-information-en": [ { "title": "About Us" }, { "link": "/content/aboutus" } ], ................... ................... ................... } }
- Status:
- Error Response:
- Status:
401 Unauthorized- Reason: Authentication token is missing or invalid.
{ "error": "Failed to retrieve menu items" }
- Status:
3. GET: ../menus/{slug}
- Namespace and Imports: The controller is part of the
App\Http\Controllers\Apinamespace and utilizesContentService. - Service Dependencies: Uses
ContentServiceto 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.
- Method:
- 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": [........], ], } }
- Status:
- Error Response:
- Status:
404 Not Found- Reason: The menu item with the specified slug does not exist.
{ "error": "Menu item not found" }
- Reason: The menu item with the specified slug does not exist.
4. GET: ../pages/{slug}
- Namespace and Imports: The controller is part of the
App\Http\Controllers\Apinamespace and utilizesContentService. - Service Dependencies
ContentServiceto 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.
- Method:
- 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, ......., } ] }
- Status:
- Error Response:
- Status:
404 Not Found- Reason: The page with the specified slug does not exist.
{ "error": "Page not found" }
- Reason: The page with the specified slug does not exist.
5. POST: ../pages-meta/{slug}
- Namespace and Imports: The controller is part of the
App\Http\Controllers\Apinamespace and imports necessary classes includingFetchContentRequest,Response, andLog. - Service Dependencies
ContentServiceto 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"] }
- Method:
- Request:
- Positive Response:
- Status:
200 OK - Response:
Example POST->https://base_url/ecom/v1/pages-meta/terms { "data": { "web_url": "/content/terms" }, }
- Status:
- 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
keysparameter is missing or invalid. - Response:
{ "error": "Page meta information not found" }
- Reason: The request body is malformed or the
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
getPageMetaBySlugmethod 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\Apinamespace and utilizesContentService. - Service Dependencies
ContentServiceto 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.
- Method:
- 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", ........................., .......................... } }
- Status:
- Error Response:
- Status:
404 Not Found- Reason: The post with the specified slug does not exist.
{ "error": "Post not found" }
- Reason: The post with the specified slug does not exist.
7. GET: ../categories/{slug}/posts
- Namespace and Imports: The controller is part of the
App\Http\Controllers\Apinamespace and utilizesContentService. - Service Dependencies
ContentServiceto 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.
- Method:
- 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 } ] } }, ] }
- Status:
- 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\Apinamespace and utilizesContentService. - Service Dependencies
ContentServiceto 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.
- Method:
- 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, ......., } ] }
- Status:
- Error Response:
- Status:
404 Not Found- Reason: The archive with the specified slug does not exist.
{ "error": "Resource Not Found" }
- Reason: The archive with the specified slug does not exist.
9.GET: ../archive-links
- Namespace and Imports: The controller is part of the
App\Http\Controllers\Apinamespace and utilizesContentService. - 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
- Method:
- Example Request
GET /content/archive-links Authorization: Bearer {token} - Response:
- Status:
200 OK - Response:
{ "data": [ { ....................... }, { .................... } ] }
- Status:
- Error Response:
- Status:
401 Unauthorized- Reason: Authentication token is missing or invalid.
{ "error": "Resource Not Found" }
- Reason: Authentication token is missing or invalid.
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\Apinamespace. It imports necessary classes and interfaces includingRedirectResource,Request,Cache, andRedirect. - Service Dependencies
the Redirect modelto retrieve redirect data andRedirectResourceto 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-Typeheader set toapplication/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.
- Method:
- 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 } ] }
- Status:
- Example Usage:
The
RedirectResourceis used in the RedirectController to format the data for the/redirectsendpoint. - Example Transformation:
Given a
Redirectmodel instance with the following properties:from=/old-pageto=/new-pagepreserveQueryString=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\Apinamespace and imports necessary classes includingCache,Response, andBrandService. - Service Dependencies
BrandServiceto 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-Typeheader set toapplication/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.
- Method:
- 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", .......... } }
- Status:
- Caching Details:
- Cache Key: '
website.content.brands' - TTL (Time To Live): Defined by the
content.brands_cache_ttlconfiguration value. - Fallback
cache is not available, the BrandServiceis queried to fetch the brands.
- Cache Key: '
- 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.