Search

Search

Returns a collection of relevant data matching a specified query. If no parameters are passed, it thrown an error. Otherwise, it lists the documents in the collection matching the specified parameters:

Search API Playground

The API playground is an interactive environment to make requests and preview an API endpoint.

q

Tes endpoint search with q as param

Method : GET

URL : /api/search?q=noah

Request :

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};
 
fetch("http://localhost:3000/api/search?q=noah", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Response : 200 - OK

{
  "songs": [],
  "albums": [],
  "artists": [
    {
      "id": 1,
      "created_at": "2022-07-06T10:43:42+00:00",
      "name": "Noah",
      "cover_url": "https://i.scdn.co/image/ab6761610000e5eba8fe25ec607f3cca02f5db6c",
      "genre_id": 1
    }
  ],
  "playlists": [
    {
      "id": 1,
      "user_id": null,
      "name": "Noah Top 10 ",
      "created_at": "2023-01-04T05:56:57.40715+00:00",
      "playlist_song": [
        {
          "id": 19,
          "playlist_id": 1,
          "song_id": 2,
          "created_at": "2023-01-04T08:57:27.606081+00:00"
        }
      ]
    }
  ]
}

URL : /api/search?q=bintang

Request :

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};
 
fetch("http://localhost:3000/api/search?q=bintang", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Response : 200 - OK

{
  "songs": [
    {
      "id": 2,
      "name": "Bintang Di Surga",
      "youtube_url": "B1ynHmn0XZ4",
      "cover_url": "https://i.scdn.co/image/ab67616d00001e02af69d9e82cc973f608481610",
      "artist_id": 1,
      "created_at": "2022-07-06T10:38:10+00:00",
      "album_id": 1,
      "preview_url": "https://p.scdn.co/mp3-preview/09474fc657c15038cb699afa4a52b4fac9383d62",
      "artist_name": "Noah"
    },
    {
      "id": 16,
      "name": "Aku & Bintang",
      "youtube_url": "4jO1t6QMYfg",
      "cover_url": "https://i.scdn.co/image/ab67616d0000b27324496b7707e9304c4ad76c5a",
      "artist_id": 1,
      "created_at": "2023-01-04T06:00:41.095572+00:00",
      "album_id": 3,
      "preview_url": "https://p.scdn.co/mp3-preview/a84561968341bc5cebdc98bacebd104e8dcc5856",
      "artist_name": "Noah"
    }
  ],
  "albums": [
    {
      "id": 1,
      "created_at": "2022-12-22T13:41:57.364685+00:00",
      "name": "Bintang di Surga",
      "cover": "https://i.scdn.co/image/ab67616d00001e02af69d9e82cc973f608481610",
      "updated_at": "2022-12-22T13:41:57.364685",
      "artists_id": 1,
      "artist_name": "Noah"
    }
  ],
  "artists": [],
  "playlists": []
}

Response :

{
    "error_code": "404",
    "message": "Not Found",
    "songs": [],
    "albums": [],
    "artists": [],
    "playlists": []
}