### Example: Search for 'foo' stories Source: https://hn.algolia.com/api An example demonstrating how to search for all stories containing the word 'foo'. This utilizes the `query` and `tags` parameters. ```HTTP http://hn.algolia.com/api/v1/search?query=foo&tags=story ``` -------------------------------- ### Example: Search for 'bar' URLs Source: https://hn.algolia.com/api An example demonstrating how to search for items where the URL contains 'bar'. This uses the `query` and `restrictSearchableAttributes` parameters. ```HTTP http://hn.algolia.com/api/v1/search?query=bar&restrictSearchableAttributes=url ``` -------------------------------- ### Example: Search for the latest stories Source: https://hn.algolia.com/api An example to retrieve the most recent stories posted on Hacker News. This uses the `search_by_date` endpoint with `tags=story`. ```HTTP http://hn.algolia.com/api/v1/search_by_date?tags=story ``` -------------------------------- ### Example: Search for latest stories or polls Source: https://hn.algolia.com/api An example to retrieve the most recent stories or polls on Hacker News. This demonstrates using OR logic with the `tags` parameter. ```HTTP http://hn.algolia.com/api/v1/search_by_date?tags=(story,poll) ``` -------------------------------- ### Example: Search for 'bar' comments Source: https://hn.algolia.com/api An example showing how to search for all comments containing the word 'bar'. This uses the `query` and `tags` parameters to filter for comments. ```HTTP http://hn.algolia.com/api/v1/search?query=bar&tags=comment ``` -------------------------------- ### Example: Search for current front page stories Source: https://hn.algolia.com/api An example to retrieve all stories currently featured on the Hacker News front page. This uses the `tags=front_page` parameter. ```HTTP http://hn.algolia.com/api/v1/search?tags=front_page ``` -------------------------------- ### Example: Search for stories by a specific author Source: https://hn.algolia.com/api An example to find all stories authored by a specific user, 'pg'. This uses the `search` endpoint with `tags=story,author_pg`. ```HTTP http://hn.algolia.com/api/v1/search?tags=story,author_pg ``` -------------------------------- ### Example: Search for 'pg' with pagination Source: https://hn.algolia.com/api An example of a search query for 'pg' that includes pagination parameters. It shows the structure of the response, including `hits`, `page`, `nbHits`, `nbPages`, and `hitsPerPage`. ```JSON { "hits": [ { "title": "Y Combinator", "url": "http://ycombinator.com", "author": "pg", "points": 57, "story_text": null, "comment_text": null, "_tags": [ "story" ], "num_comments": 2, "objectID": "1", "_highlightResult": { "title": { "value": "Y Combinator", "matchLevel": "none", "matchedWords": [] }, "url": { "value": "http://ycombinator.com", "matchLevel": "none", "matchedWords": [] }, "author": { "value": "pg", "matchLevel": "full", "matchedWords": [ "pg" ] } } }, [...] ], "page": 0, "nbHits": 11, "nbPages": 1, "hitsPerPage": 20, "processingTimeMS": 1, "query": "pg", "params": "query=pg" } ``` -------------------------------- ### Example: Search for stories within a timestamp range Source: https://hn.algolia.com/api An example to find stories created between two Unix timestamps. This uses the `search_by_date` endpoint and `numericFilters` for `created_at_i`. ```HTTP http://hn.algolia.com/api/v1/search_by_date?tags=story&numericFilters=created_at_i>X,created_at_iX ``` -------------------------------- ### Get Item by ID Source: https://hn.algolia.com/api Retrieves a specific Hacker News item (story, comment, etc.) by its unique ID. ```APIDOC ## GET /api/v1/items/:id ### Description Retrieves a specific Hacker News item by its unique ID. ### Method GET ### Endpoint `http://hn.algolia.com/api/v1/items/:id` ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the item. ### Response #### Success Response (200) - **id** (integer) - The item's unique identifier. - **created_at** (string) - The creation timestamp of the item. - **author** (string) - The username of the item's author. - **title** (string) - The title of the item (for stories). - **url** (string) - The URL associated with the item (for stories). - **text** (string) - The text content of the item (for comments). - **points** (integer) - The score of the item. - **parent_id** (integer) - The ID of the parent item (for comments). - **children** (array) - An array of child items (replies). #### Response Example ```json { "id": 1, "created_at": "2006-10-09T18:21:51.000Z", "author": "pg", "title": "Y Combinator", "url": "http://ycombinator.com", "text": null, "points": 57, "parent_id": null, "children": [ { "id": 15, "created_at": "2006-10-09T19:51:01.000Z", "author": "sama", "text": ""the rising star of venture capital" -unknown VC eating lunch on SHR", "points": 5, "parent_id": 1, "children": [ { "id": 17, "created_at": "2006-10-09T19:52:45.000Z", "author": "pg", "text": "Is there anywhere to eat on Sandhill Road?", "points": 5, "parent_id": 15, "children": [] } ] } ] } ``` ``` -------------------------------- ### Get User by Username Source: https://hn.algolia.com/api Retrieves information about a Hacker News user by their username. ```APIDOC ## GET /api/v1/users/:username ### Description Retrieves information about a Hacker News user by their username. ### Method GET ### Endpoint `http://hn.algolia.com/api/v1/users/:username` ### Parameters #### Path Parameters - **username** (string) - Required - The username of the user. ### Response #### Success Response (200) - **username** (string) - The user's username. - **about** (string) - A short biography of the user. - **karma** (integer) - The user's karma score. #### Response Example ```json { "username": "pg", "about": "PG's bio", "karma": 99999 } ``` ``` -------------------------------- ### Retrieve a Hacker News Item by ID Source: https://hn.algolia.com/api Fetches a specific Hacker News item (story, comment, etc.) using its unique ID. This endpoint is useful for getting detailed information about a single post or comment. ```HTTP GET http://hn.algolia.com/api/v1/items/:id ``` -------------------------------- ### Search Hacker News (Relevance) Source: https://hn.algolia.com/api Searches Hacker News stories and comments, sorted by relevance, then points, then number of comments. ```APIDOC ## GET /api/v1/search ### Description Searches Hacker News stories and comments, sorted by relevance, then points, then number of comments. ### Method GET ### Endpoint `http://hn.algolia.com/api/v1/search` ### Parameters #### Query Parameters - **query** (string) - Required - The full-text search query. - **tags** (string) - Optional - Filters results by tags (e.g., `story`, `comment`, `author_:USERNAME`). Tags can be ANDed by default or ORed using parentheses. - **numericFilters** (string) - Optional - Filters results by numerical conditions (e.g., `created_at_i>X`, `points=100`). Available fields: `created_at_i`, `points`, `num_comments`. - **page** (integer) - Optional - The page number for pagination. Defaults to 0. ### Response #### Success Response (200) - **hits** (array) - An array of search results. - **page** (integer) - The current page number. - **nbHits** (integer) - The total number of hits found. - **nbPages** (integer) - The total number of pages. - **hitsPerPage** (integer) - The number of hits per page. - **processingTimeMS** (integer) - The time taken to process the request in milliseconds. - **query** (string) - The original query parameters. - **params** (string) - The formatted parameters used for the search. #### Response Example ```json { "hits": [ { "title": "Y Combinator", "url": "http://ycombinator.com", "author": "pg", "points": 57, "story_text": null, "comment_text": null, "_tags": ["story"], "num_comments": 2, "objectID": "1", "_highlightResult": { "title": { "value": "Y Combinator", "matchLevel": "none", "matchedWords": [] }, "url": { "value": "http://ycombinator.com", "matchLevel": "none", "matchedWords": [] }, "author": { "value": "pg", "matchLevel": "full", "matchedWords": ["pg"] } } } ], "page": 0, "nbHits": 11, "nbPages": 1, "hitsPerPage": 20, "processingTimeMS": 1, "query": "pg", "params": "query=pg" } ``` ``` -------------------------------- ### Search Hacker News (By Date) Source: https://hn.algolia.com/api Searches Hacker News stories and comments, sorted by date, with the most recent first. ```APIDOC ## GET /api/v1/search_by_date ### Description Searches Hacker News stories and comments, sorted by date, with the most recent first. ### Method GET ### Endpoint `http://hn.algolia.com/api/v1/search_by_date` ### Parameters #### Query Parameters - **query** (string) - Optional - The full-text search query. - **tags** (string) - Optional - Filters results by tags (e.g., `story`, `comment`, `author_:USERNAME`). Tags can be ANDed by default or ORed using parentheses. - **numericFilters** (string) - Optional - Filters results by numerical conditions (e.g., `created_at_i>X`, `points=100`). Available fields: `created_at_i`, `points`, `num_comments`. - **page** (integer) - Optional - The page number for pagination. Defaults to 0. ### Response #### Success Response (200) - **hits** (array) - An array of search results. - **page** (integer) - The current page number. - **nbHits** (integer) - The total number of hits found. - **nbPages** (integer) - The total number of pages. - **hitsPerPage** (integer) - The number of hits per page. - **processingTimeMS** (integer) - The time taken to process the request in milliseconds. - **query** (string) - The original query parameters. - **params** (string) - The formatted parameters used for the search. #### Response Example ```json { "hits": [ { "title": "Example Story", "url": "http://example.com", "author": "user123", "points": 10, "story_text": null, "comment_text": null, "_tags": ["story"], "num_comments": 1, "objectID": "12345", "_highlightResult": { "title": { "value": "Example Story", "matchLevel": "none", "matchedWords": [] } } } ], "page": 0, "nbHits": 50, "nbPages": 3, "hitsPerPage": 20, "processingTimeMS": 5, "query": "", "params": "tags=story" } ``` ``` -------------------------------- ### Search Hacker News by Date Source: https://hn.algolia.com/api Performs a search across Hacker News, sorted by date with the most recent results first. This is ideal for finding the latest posts or comments. ```HTTP GET http://hn.algolia.com/api/v1/search_by_date?query=... ``` -------------------------------- ### Search Hacker News Stories by Relevance Source: https://hn.algolia.com/api Performs a search across Hacker News stories, sorted by relevance, then points, then number of comments. This is the default search behavior. ```HTTP GET http://hn.algolia.com/api/v1/search?query=... ``` -------------------------------- ### Retrieve a Hacker News User by Username Source: https://hn.algolia.com/api Fetches information about a specific Hacker News user, including their username, about section, and karma. This is useful for understanding user activity and profiles. ```HTTP GET http://hn.algolia.com/api/v1/users/:username ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.