Angular Rest Http Module with Typescript Declarative Annotations, Guards, Handlers and more
or
@Client()
decorator marks a class as RestClient and provides functionality to make Http calls with its marked methods.
This decorator also marks the class as Injectable()
and makes it to function as an Angular Service.
It can be configured by defining a ClientOptions
object as a parameter
A ClientOptions
object configures base options for the rest methods declared inside a @Client()
class
All of these decorators marks a method in a @Client()
as a request builder. path
can be specified to define the endpoint path. Otherwise, the method name is going to be used as path.
The method return type should be defined as Promise
and function should be empty but only returning null
. Decorators will handle all the rest.
@Get(path?: string)
@Post(path?: string)
@Put(path?: string)
@Delete(path?: string)
@Patch(path?: string)
@Options(path?: string)
@Head(path?: string)
@Jsonp(path?: string)
Example:
Mark a parameter with @Body()
decorator to fill body object with it.
A FormData
instance can be used for image uploads etc.
Body
decorator can be used in only POST, PUT, PATCH requests
Example:
Mark a parameter decorated with Path
to replace the specified key in the url
Example:
to be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
Guards run just before a request has been sent to check whether request should be sent or not
Guards can be a function, a method of a client or an injectable of RestGuard
Define an injectable as a rest guard and declare them as a guard (Base Guard, Client Guard, Method Guard) to check a request can be sent or not.
Don't forget to provide them in a module
Example:
A single function can be a rest guard if it accepts first param as HttpRequest<any>
and returns whether boolean
or Promise<boolean>
Example:
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
To be determined
In client constructor functions, calling a rest call is forbidden. Because the client dependencies have not been set yet when the constructor function called.
To run some code when client instance created, @OnClientReady()
decorator can be used. It will mark a method of a client to be called right after construction.
Example:
Defines whether a request should be sent with outgoing credentials (cookies). Default true
It can be set in module config as base option. That would configure for all requests unless it is declared especially by other methods.
Example:
It can be provided with the BASE_WITH_CREDENTIALS
token as base option. That would also configure for all requests like As Module Config unless it is declared especially by other methods.
Example:
It can be set in @Client()
decorator as an option. That would configure withCredentials option for all the calls in that client.
Example:
It can be set by @WithCredentials()
decorator on top a rest call. That would configure withCredentials option for only that call.
Example:
to be developed
This package supports aot builds, however there are some limitations.
Injector
should have been defined as the first parameter for every @Client
constructor.RestModule.forRoot
static method. All of these should be provided in module providersAli Şahin Özçelik
This repository is started as a fork of steven166/angular-rest-client and completely refactored now
MIT