Skip to content

Instantly share code, notes, and snippets.

@JanPlazovnik
Created June 5, 2022 09:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
TypeScript implementation of the JSend specification
export interface ApiResponse {
status: 'success' | 'fail' | 'error';
data?: any;
message?: any;
}
export class jsend {
// https://github.com/omniti-labs/jsend
public static success(data: any): ApiResponse {
return {
status: 'success',
data,
};
}
public static fail(data: any): ApiResponse {
return {
status: 'fail',
data,
};
}
public static error(message: string | null, data?: any): ApiResponse {
return {
status: 'error',
message,
data,
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment