Skip to content

API interface

0ojixueseno0 edited this page Dec 2, 2022 · 2 revisions

API interface

Header

Content-Type: application/json; charset=utf-8

Access-Control-Allow-Origin: <config.allowOrigin>

Access-Control-Allow-Credentials: true

Interface

  • GET /api/ - Get the API interface which is currently enabled.

    example:

    {
      "type": "apiInfo",
      "data": {
        "enabled": [
          "getInfo",
          "getPostCount",
          "getPosts",
          "getPostsByCategory",
          "getPostsByCategoryId",
          "getPostsByTag",
          "getPostsByTagId",
          "getPostByPath",
          "getPostById",
          "getCategories",
          "getTags"
        ]
      }
    }
  • GET /api/getInfo/ - Get the information of the current site.

    example:

    {
      "type": "getInfo",
      "data": {
        "title": "Hexo中文测试",
        "subtitle": "",
        "description": "",
        "author": "John Doe",
        "language": "en",
        "timezone": "",
        "url": "http://example.com"
      }
    }
  • GET /api/getPostCount/ - Get the number of posts.

    example:

    {
      "type": "getPostCount",
      "data": {
        "count": 10
      }
    }
  • GET /api/getPosts/ - Get the posts list.

    responsedata.data.posts: Array

    post:

    {
        title: String,
        date: String,
        description: String,
        categories: Array,
        tags: Array,
        _path: String,
        _link: String,
        _id: String
    }

    example:

    {
      "type": "getPosts",
      "data": {
        "posts": [
          {
            "title": "1",
            "date": "2022-09-06T01:24:03.000Z",
            "description": "",
            "categories": [
              { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" },
              { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" }
            ],
            "tags": [
              { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" },
              { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" },
              { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" }
            ],
            "_path": "2022/09/06/1/",
            "_link": "http://example.com/2022/09/06/1/",
            "_id": "cl7pldj300000p08detj8etxb"
          },
          {
            "title": "2",
            "date": "2022-09-06T01:24:04.000Z",
            "description": "",
            "categories": [],
            "tags": [],
            "_path": "2022/09/06/2/",
            "_link": "http://example.com/2022/09/06/2/",
            "_id": "cl7pldj340001p08d6o7a7z1w"
          },
          {
            "title": "Hello World",
            "date": "2022-09-06T01:22:20.002Z",
            "description": "",
            "categories": [],
            "tags": [],
            "_path": "2022/09/06/hello-world/",
            "_link": "http://example.com/2022/09/06/hello-world/",
            "_id": "cl7pldj3h0009p08dcmvx29lk"
          }
        ]
      }
    }
  • GET /api/getPostsByCategory/:category - Get the posts list by category.

    example:

    {
      "type": "getPostsByCategory",
      "data": [
        {
          "title": "1",
          "date": "2022-09-06T01:24:03.000Z",
          "description": "",
          "categories": [
            { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" },
            { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" }
          ],
          "tags": [
            { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" },
            { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" },
            { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" }
          ],
          "_path": "2022/09/06/1/",
          "_link": "http://example.com/2022/09/06/1/",
          "_id": "cl7pldj300000p08detj8etxb"
        }
      ]
    }
  • GET /api/getPostsByCategoryId/:categoryId - Get the posts list by category id.

    example: (same as getPostsByCategory)

  • GET /api/getPostsByTag/:tag - Get the posts list by tag.

    example:

    {
      "type": "getPostsByTag",
      "data": [
        {
          "title": "1",
          "date": "2022-09-06T01:24:03.000Z",
          "description": "",
          "categories": [
            { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" },
            { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" }
          ],
          "tags": [
            { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" },
            { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" },
            { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" }
          ],
          "_path": "2022/09/06/1/",
          "_link": "http://example.com/2022/09/06/1/",
          "_id": "cl7pldj300000p08detj8etxb"
        }
      ]
    }
  • GET /api/getPostsByTagId/:tagId - Get the posts list by tag id.

    example: (same as getPostsByTag)

  • GET /api/getPostByPath/:path - Get the post by path.

    example:

    {
      "type": "getPostByPath",
      "data": {
        "title": "Hello World",
        "date": "2022-09-06T01:22:20.002Z",
        "description": "",
        "categories": [],
        "tags": [],
        "content": "...html document...",
        "_id": "cl7pldj3h0009p08dcmvx29lk"
      }
    }
  • GET /api/getPostById/:id - Get the post by id.

    example: (same as getPostByPath)

  • GET /api/getCategories/ - Get the categories list.

    example:

    {
      "type": "getCategories",
      "data": [
        { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" },
        { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" }
      ]
    }
  • GET /api/getTags/ - Get the tags list.

    example:

    {
      "type": "getTags",
      "data": {
        "tags": [
          { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" },
          { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" },
          { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" }
        ]
      }
    }
  • GET /api/getLatestPost/ - Get the latest published post.

    example:

    {
      "type": "getLatestPost",
      "data": {
        "title": "test_2_9",
        "date": "2022-08-22T00:55:51.000Z",
        "description": "",
        "categories": [],
        "tags": [],
        "content": "...html document...",
        "_path": "posts/c3f5fdb8.html",
        "_link": "https://example.com/posts/c3f5fdb8.html",
        "_id": "cl741rujl00087wnd0tzbhlb8"
      }
    }
  • GET /api/getLatest5Posts/ - Get the latest 5 published posts.

    example:

    {
      "type": "getLatest5Posts",
      "data": [
        {
          "title": "test_2_9",
          "date": "2022-08-22T00:55:51.000Z",
          "description": "",
          "categories": [],
          "tags": [],
          "_path": "posts/c3f5fdb8.html",
          "_link": "https://example.com/posts/c3f5fdb8.html",
          "_id": "cl741rujl00087wnd0tzbhlb8"
        },
        {
          "title": "test_2_8",
          "date": "2022-08-22T00:55:49.000Z",
          "description": "",
          "categories": [],
          "tags": [],
          "_path": "posts/b4f2cd2e.html",
          "_link": "https://example.com/posts/b4f2cd2e.html",
          "_id": "cl741rujj00077wnd443d1lub"
        },
        {
          "title": "test_2_7",
          "date": "2022-08-22T00:55:48.000Z",
          "description": "",
          "categories": [],
          "tags": [],
          "_path": "posts/244dd0bf.html",
          "_link": "https://example.com/posts/244dd0bf.html",
          "_id": "cl741ruji00067wndfrpke0ye"
        },
        {
          "title": "test_2_6来点中文",
          "date": "2022-08-22T00:55:46.000Z",
          "description": "",
          "categories": [],
          "tags": [],
          "_path": "posts/534ae029.html",
          "_link": "https://example.com/posts/534ae029.html",
          "_id": "cl741ruji00057wndghfnhfxe"
        },
        {
          "title": "test_2_5",
          "date": "2022-08-22T00:55:44.000Z",
          "description": "",
          "categories": [],
          "tags": [],
          "_path": "posts/ca43b193.html",
          "_link": "https://example.com/posts/ca43b193.html",
          "_id": "cl741rujh00047wnd2x9o2xye"
        }
      ]
    }