GoHadits is a simple open-source API built using Golang to access a collection of Hadiths.
Read this in other languages: Bahasa Indonesia.
This project is built using Go version 1.22.2, and it is expected to be developed using this specific version of Golang to ensure the desired outcome.
- Install project dependencies using the command
go mod download
. - Run the service using the command
go run .
orgo run main.go
.
Execute the following command to build the binary:
go build -ldflags "-s -w" -o ./out .
Then you can run the service using the command ./out
.
Returning a list of available hadith books.
The response will be returned an JSON. For example:
{
"code": 200,
"data": [
{
"book": "bukhari",
"name": "Bukhari",
"total": 6638
},
{
"book": "muslim",
"name": "Muslim",
"total": 4930
}
],
"message": "Hadith books successfully retrieved.",
"status": "success"
}
The response will be returned as JSON in case of an error. For example:
{
"code": 500,
"message": "Internal Server Error",
"status": "error"
}
Returning a list of hadiths found in the requested book.
Name | Required | Type | Description |
---|---|---|---|
book |
required | param | Book name. ( data[i].book from api/v1/hadith ) |
limit |
optional | query | Specifies the number of hadith to fetch per request. The default is 50 and the maximum is 150 . |
offset |
optional | query | Specifies the starting point (offset) from where to fetch the items. The default is 0 . |
The response will be returned an JSON. For example:
{
"code": 200,
"data": {
"contents": [
{
"number": 1,
"arab": "حَدَّثَنَا عَبْدُ اللَّهِ بْنُ مَسْلَمَةَ بْنِ قَعْنَبٍ الْقَعْنَبِيُّ حَدَّثَنَا عَبْدُ الْعَزِيزِ يَعْنِي ابْنَ مُحَمَّدٍ عَنْ مُحَمَّدٍ يَعْنِي ابْنَ عَمْرٍو عَنْ أَبِي سَلَمَةَ عَنْ الْمُغِيرَةِ بْنِ شُعْبَةَأَنَّ النَّبِيَّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ كَانَ إِذَا ذَهَبَ الْمَذْهَبَ أَبْعَدَ",
"id": "Telah menceritakan kepada kami [Abdullah bin Maslamah bin Qa'nab al Qa'nabi] telah menceritakan kepada kami [Abdul Aziz yakni bin Muhammad] dari [Muhammad yakni bin Amru] dari [Abu Salamah] dari [Al Mughirah bin Syu'bah] bahwasanya Nabi shallallahu 'alaihi wasallam apabila hendak pergi untuk buang hajat, maka beliau menjauh."
}
],
"limit": 1,
"name": "Abu Dawud",
"offset": 0,
"total": 4419
},
"message": "Hadith collection of Abu Dawud successfully retrieved.",
"status": "success"
}
The response will be returned as JSON in case of an error. For example:
{
"code": 400,
"message": "offset should not larger than total hadith available",
"status": "error"
}
Returning a specific hadith according to the given hadith number.
Name | Required | Type | Description |
---|---|---|---|
book |
required | param | Book name. ( data[i].book from api/v1/hadith ) |
number |
required | param | Hadith number. |
The response will be returned an JSON. For example:
{
"code": 200,
"data": {
"content": {
"number": 5,
"arab": "حَدَّثَنَا عَمْرُو بْنُ مَرْزُوقٍ أَخْبَرَنَا شُعْبَةُ عَنْ قَتَادَةَ عَنْ النَّضِرِ بْنِ أَنَسٍ عَنْ زَيْدِ بْنِ أَرْقَمَعَنْ رَسُولِ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ قَالَ إِنَّ هَذِهِ الْحُشُوشَ مُحْتَضَرَةٌ فَإِذَا أَتَى أَحَدُكُمْ الْخَلَاءَ فَلْيَقُلْ أَعُوذُ بِاللَّهِ مِنْ الْخُبُثِ وَالْخَبَائِثِ",
"id": "Telah menceritakan kepada kami [Amru bin Marzuq] telah mengabarkan kepada kami [Syu'bah] dari [Qatadah] dari [an Nadhr bin Anas] dari [Zaid bin Arqam] dari Rasulullah shallallahu 'alaihi wasallam, beliau bersabda: \"Sesungguhnya tempat buang hajat itu dihadiri oleh setan-setan, maka apabila salah seorang dari kalian mendatangi WC, hendaklah dia mengucapkan; 'Aku berlindung kepada Allah dari setan jantan dan setan betina'.\""
},
"name": "Abu Dawud",
"total": 4419
},
"message": "Hadith no. 5 from book of Abu Dawud successfully retrieved.",
"status": "success"
}
The response will be returned as JSON in case of an error. For example:
{
"code": 404,
"message": "hadith no. 5000 from book of Abu Dawud is not found",
"status": "error"
}
Returning a random hadith.
The response will be returned an JSON. For example:
{
"code": 200,
"data": {
"content": {
"number": 5,
"arab": "حَدَّثَنَا عَمْرُو بْنُ مَرْزُوقٍ أَخْبَرَنَا شُعْبَةُ عَنْ قَتَادَةَ عَنْ النَّضِرِ بْنِ أَنَسٍ عَنْ زَيْدِ بْنِ أَرْقَمَعَنْ رَسُولِ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ قَالَ إِنَّ هَذِهِ الْحُشُوشَ مُحْتَضَرَةٌ فَإِذَا أَتَى أَحَدُكُمْ الْخَلَاءَ فَلْيَقُلْ أَعُوذُ بِاللَّهِ مِنْ الْخُبُثِ وَالْخَبَائِثِ",
"id": "Telah menceritakan kepada kami [Amru bin Marzuq] telah mengabarkan kepada kami [Syu'bah] dari [Qatadah] dari [an Nadhr bin Anas] dari [Zaid bin Arqam] dari Rasulullah shallallahu 'alaihi wasallam, beliau bersabda: \"Sesungguhnya tempat buang hajat itu dihadiri oleh setan-setan, maka apabila salah seorang dari kalian mendatangi WC, hendaklah dia mengucapkan; 'Aku berlindung kepada Allah dari setan jantan dan setan betina'.\""
},
"name": "Abu Dawud",
"total": 4419
},
"message": "Hadith no. 5 from book of Abu Dawud successfully retrieved.",
"status": "success"
}
The response will be returned as JSON in case of an error. For example:
{
"code": 404,
"message": "hadith no. 5000 from book of Abu Dawud is not found",
"status": "error"
}
GoHadith is open-sourced software licensed under the MIT license.