Skip to content

Commit

Permalink
Merge branch 'master' of github.com:evert/ketting
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Nov 2, 2019
2 parents 21d4eac + 2def2ce commit 24e4937
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Ketting - A hypermedia client for javascript
============================================

[![Greenkeeper badge](https://badges.greenkeeper.io/evert/ketting.svg)](https://greenkeeper.io/)

Introduction
------------

Expand Down
17 changes: 13 additions & 4 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export default class Resource<TResource = any, TPatch = Partial<TResource>> {
* If no Location header was given, it will resolve still, but with an empty
* value.
*/
async post<TPostResource = any>(body: TPostResource): Promise<Resource<TPostResource>|null> {
post(body: any): Promise<Resource | null>;
post<TPostResource>(body: any): Promise<Resource<TPostResource>>;
async post(body: any): Promise<Resource | null> {

const contentType = this.contentType || this.client.contentTypes[0].mime;
const response = await this.fetchAndThrow(
Expand All @@ -131,10 +133,17 @@ export default class Resource<TResource = any, TPatch = Partial<TResource>> {
}
);

if (response.headers.has('location')) {
return this.go(<string> response.headers.get('location'));
switch (response.status) {
case 205 :
return this;
case 201:
if (response.headers.has('location')) {
return this.go(<string> response.headers.get('location'));
}
return null;
default:
return null;
}
return null;

}

Expand Down

0 comments on commit 24e4937

Please sign in to comment.