Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

    <The request type>

    GET | POST | DELETE | PUT

  • URL Params

    <If URL params exist, specify them in accordance with name mentioned in URL section. Separate into optional and required. Document data constraints.>

    Required:

    id=[integer]

    Optional:

    photo_id=[alphanumeric]

  • Data Params

    <If making a post request, what should the body payload look like? URL Params rules apply here too.>

  • Success Response:

    <What should the status code be on success and is there any returned data? This is useful when people need to to know what their callbacks should expect!>

    • Code: 200
      Content: { id : 12 }
  • Error Response:

    <Most endpoints will have many ways they can fail. From unauthorized access, to wrongful parameters etc. All of those should be liste d here. It might seem repetitive, but it helps prevent assumptions from being made where they should be.>

    • Code: 401 UNAUTHORIZED
      Content: { error : "Log in" }

    OR

    • Code: 422 UNPROCESSABLE ENTRY
      Content: { error : "Email Invalid" }
  • Sample Call:

    <Just a sample call to your endpoint in a runnable format ($.ajax call or a curl request) - this makes life easier and more predictable.>

  • Notes:

    <This is where all uncertainties, commentary, discussion etc. can go. I recommend timestamping and identifying oneself when leaving comments here.>

Show User

Returns json data about a single user.

  • URL

    /users/:id

  • Method:

    GET

  • URL Params

    Required:

    id=[integer]

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content: { id : 12, name : "Michael Bloom" }
  • Error Response:

    • Code: 404 NOT FOUND
      Content: { error : "User doesn't exist" }

    OR

    • Code: 401 UNAUTHORIZED
      Content: { error : "You are unauthorized to make this request." }
  • Sample Call:

      $.ajax({
        url: "/users/1",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
@599316527
Copy link

599316527 commented Nov 9, 2018

How to specify request/response headers

@v4lerio
Copy link

v4lerio commented Jan 10, 2019

Thanks for sharing

@piny4man
Copy link

piny4man commented Feb 25, 2019

🥇 🙏 Thanks!

@bitfishxyz
Copy link

bitfishxyz commented Mar 12, 2019

Sometimes, you can write you error response in an indepentant place

@clombardi
Copy link

clombardi commented Apr 8, 2019

Thanks a lot, I am using this template to document an API to be released soon.

@Jaymo
Copy link

Jaymo commented Apr 25, 2019

Thanks for sharing this, using it to document APIs I use

@camilamiz
Copy link

camilamiz commented May 8, 2019

Thank you so much! Very useful!

@raulinoneto
Copy link

raulinoneto commented May 10, 2019

Thank you!! I'll use it

@phungrk
Copy link

phungrk commented May 24, 2019

Thank you!!

@KyleXID
Copy link

KyleXID commented Jun 24, 2019

Thank you for sharing !!!

@kkkumarkanike
Copy link

kkkumarkanike commented Oct 15, 2019

shall I know where is the endpoint URL of GitHub API

@anibal21
Copy link

anibal21 commented Dec 27, 2019

Thanks!

@itsRealoj
Copy link

itsRealoj commented Apr 30, 2020

Thanks a lot

@sangelesgu
Copy link

sangelesgu commented May 27, 2020

Thanks! Amazing example!

@DeepakDG
Copy link

DeepakDG commented Jun 13, 2020

This is what I was looking for..Thanks..Great work

@thirupathi-chintu
Copy link

thirupathi-chintu commented Oct 6, 2020

Awesome!

@Atlantisland
Copy link

Atlantisland commented Oct 11, 2020

Thank you so much!

@ZmlAlex
Copy link

ZmlAlex commented Oct 19, 2020

Thanks!

@candidosales
Copy link

candidosales commented Oct 23, 2020

Thanks!!

@azagniotov
Copy link

azagniotov commented Mar 19, 2021

I got inspired by this Gist, so thank you, @iros!
Then I ended up creating something a-la Swagger-ish (maybe?) looking in Markdown using expandable sections, have a look:
https://gist.github.com/azagniotov/a4b16faf0febd12efbc6c3d7370383a6

or the actual API docs: https://stubby4j.com/docs/admin_portal.html#creating-newoverwriting-existing-stubs--proxy-configs

@zikrianbia
Copy link

zikrianbia commented Mar 29, 2021

Thank you

@uviigideon
Copy link

uviigideon commented Apr 20, 2021

Great helpful! Thanks for share.

@vncsna
Copy link

vncsna commented Apr 30, 2021

Thanks for sharing

@sawaca96
Copy link

sawaca96 commented May 3, 2021

👍👍👍Thanks

@MonicaisHer
Copy link

MonicaisHer commented May 31, 2021

Thank you very much ;)

@urmakgkg
Copy link

urmakgkg commented Jul 26, 2021

Thank you

@ShenShu2016
Copy link

ShenShu2016 commented Jul 28, 2021

thanks

@adeisbright
Copy link

adeisbright commented Jul 29, 2021

Thank you for this

@earthkingman
Copy link

earthkingman commented Sep 24, 2021

감사합니다

@gshyeon-testworks
Copy link

gshyeon-testworks commented Dec 9, 2021

Nice format!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment