Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify error codes in Apiary Documentation?

Tags:

apiblueprint

I want to specify the various exceptions/errors that have to be returned while making an API call. How do I achieve this with Apiary.

like image 208
Harshit Avatar asked May 29 '14 06:05

Harshit


People also ask

What are the limitations of the apiary API?

Limitations: The console calls to the API aren’t direct. The data from the browser are sent to the Apiary infrastructure, the HTTP request is made from Apiary servers without the CORS limitation and the API response is sent back from Apiary servers to the browser to be shown to the user. Requirements: The API has to be accessible from the internet.

How to specify the errors in the API response?

Many people have different designs for specifying the errors in the API response - some just return status code without any response message, while some describe a simple text message in the body and others specify custom JSON schema for specifying the errors.

How do I use the apiary editor?

Using the Editor # The Apiary Editor shows a preview of your documentation while providing instant feedback to ensure correct syntax in your API document. Your API document will be parsed with warnings and errors as you type. These errors will be displayed both in the editor header and on the lines where the warnings and errors exist.

How do I use API Blueprint in apiary?

The Blueprint starts with a metadata section. The FORMAT keyword is required and denotes that document is API Blueprint. You can also add HOST, which should have value of your production API URI. This will allow you to test and debug production calls from Apiary.


2 Answers

Kyle's response is indeed correct. I will just add that if you want to add little bit more semantics to this you can write the other possible responses like this:

## POST /users/resendVerification/{userId}

Resends the user's verification code to the email address on record.

+ Response 201

+ Response 403

    Returned if the user does not have access to the requested account

    + Body

+ Response 404

    Returned if a user was not found for the given userId

    + Body

Note: The + Body is needed (even though it is empty) to distinguish the description from a message-body.

like image 193
Zdenek Avatar answered Oct 16 '22 12:10

Zdenek


I'm not aware of a specific syntax for error codes. In the past I've simply used bullet points. For example, this is my code for a re-request verification code API.

## POST /users/resendVerification/{userId}

Resends the user's verification code to the email address on record.</br>
• 403 is returned if the user does not have access to the requested account</br>
• 404 is returned if a user was not found for the given userId</br>

+ Response 201

Hope that helps.

like image 24
Kyle Clegg Avatar answered Oct 16 '22 10:10

Kyle Clegg