Skip to content

Instantly share code, notes, and snippets.

@JanPlazovnik
Created June 5, 2022 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanPlazovnik/aee052bf328000b9105600031e978da6 to your computer and use it in GitHub Desktop.
Save JanPlazovnik/aee052bf328000b9105600031e978da6 to your computer and use it in GitHub Desktop.
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