Get Posts - AmFlint/SI-Hybrid-Api GitHub Wiki

Get Posts

URL

http://212.47.231.5/posts

Http Method

GET

Headers

  • X-Access-Token: json-web-token for authenticated user.

Http Status Codes

  • 401: Authentication required
  • 404: No post found

Query Parameters

  • title: string - Query contained in the title property of places to search for
  • location: string - Query contained in the location property of places to search for
  • difficulty: integer - Difficulty of the places to search for
  • search: string, If search parameter is provided, none of the above will be taken to account, this will produce a Search Query on Posts including title or location or content containing the search string parameter.

Request

  • Request
curl -X -H "X-Access-Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTYxMzc5MDcsInVzZXJuYW1lIjoiYW1hc3NlbG90IiwidXNlcklkIjoxLCJpYXQiOjE1MTYxMzQzMDd9.789Uwt-IRWxtgRBxLtpnIifz4PQ54HcMqz7T188Wfi4" -X GET http://212.47.231.5/posts?search=Second article
  • Response
[
    {
        "id": 2,
        "title": "Second article",
        "content": "Le second article",
        "location": "Paris 75018",
        "difficulty": 2,
        "createdAt": "2018-01-17T10:45:14.000Z",
        "updatedAt": "2018-01-17T10:45:14.000Z",
        "userId": 1
    }
]
  • Request with search parameter:
curl -X -H "X-Access-Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTYxMzc5MDcsInVzZXJuYW1lIjoiYW1hc3NlbG90IiwidXNlcklkIjoxLCJpYXQiOjE1MTYxMzQzMDd9.789Uwt-IRWxtgRBxLtpnIifz4PQ54HcMqz7T188Wfi4" -X GET http://localhost:3000/posts?search=article
  • Reponse
[
    {
        "id": 2,
        "title": "Second article",
        "content": "Le second article",
        "location": "Paris 75018",
        "difficulty": 2,
        "createdAt": "2018-01-17T10:45:14.000Z",
        "updatedAt": "2018-01-17T10:45:14.000Z",
        "userId": 1
    },
    {
        "id": 3,
        "title": "Trosieme article",
        "content": "Le trosiieme article de Vincennes",
        "location": "Vincennes",
        "difficulty": 1,
        "createdAt": "2018-01-17T10:45:30.000Z",
        "updatedAt": "2018-01-17T10:45:30.000Z",
        "userId": 1
    },
    {
        "id": 4,
        "title": "4eme",
        "content": "Le trosiieme article de Vincennes",
        "location": "Vincennes",
        "difficulty": 1,
        "createdAt": "2018-01-17T13:42:25.000Z",
        "updatedAt": "2018-01-17T13:42:25.000Z",
        "userId": 1
    },
    {
        "id": 5,
        "title": "C'est un petit test",
        "content": "Article de Guadeloupe",
        "location": "Guadeloupe",
        "difficulty": 4,
        "createdAt": "2018-01-17T14:50:35.000Z",
        "updatedAt": "2018-01-17T14:50:35.000Z",
        "userId": 1
    }
]