Search code examples
githubgithub-api

GitHub - difference between `/contents/` and `/blobs/` API endpoints


I have a list of JSON files in GH to be fetched via API.

For this, I first use the /git.trees API endpoint to get a list that contains path and url info.

Next, there seem to be 2 options for getting the file contents:

  1. use the path value from the above response in the 'get repository content' API

  2. use the url value from the above response in the 'get a blob' API

Are there any conditions for which one to select in which scenario?


Solution

  • The contents API is a newer API intended to be used with UI applications that display files differently based on their type, e.g. symlinks vs regular files. It uses file’s path as a key for retrieval.

    Blobs API is older and simpler API that is used for simple file contents retrieval - no metadata. It uses files’s SHA as a key for retrieval.

    When starting with the trees API, using blobs API for content is easier because trees API provides blobs url to retrieve the the files’s content.