0.1.6 • Published 3 years ago

echofetch v0.1.6

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

EchoFetch

build status npm version npm downloads

EchoFetch is a decorator based HTTP client for browser & Node.JS based on Axios. It has been inspired by the Java library RetroFit. EchoFetch will obtain the data from an API using a decorator based system.

Documentation

You can find the full documentation here: Documentation

How does it work

EchoFetch is a thin layer on top of Axios, therefore allowing it to both run in the browser & in Node.JS. It used the ES7 Decorator-syntax to create an implementation for a set of functions inside a class.

Install the package

Using NPM:

npm install echofetch --save

Using YARN

yarn add echofetch

Whats next: Build Setup

Simple usage

class TestService extends EchoService {
    
    @GET("/path")
    getData(): EchoPromise<string> {};

    @GET("/path")
    @Queries({
        "searching": true
    })
    searchData(@Query("q") query: string): EchoPromise<string> {};
   
    @POST("/path")
    @Headers({
        "Authorization": "api-token"
    })
    createData(@Header("name") nameHeader: string, @Body() data: TestData): EchoPromise<void> {};

    @PATCH("/path/{id}")
    updateData(@Path("id") id: number, @Body() data: TestDataUpdate): EchoPromise<void> {};

    @DELETE("/path")
    deleteData(@Path("id") id: number): EchoPromise<void> {};

    @PUT("/path/{id}")
    putData(@Path("id") id: number, @Body() data: TestDataPut): EchoPromise<void> {};
    
    @FormMultipart()
    uploadImage(@FormField("image") image: File): EchoPromise<string> {};
    
    @FormUrlEncoded()
    submitForm(@FormField("username") username: string, @FormFieldObject() otherData: Data): EchoPromise<User> {};
}

const service = new EchoServiceBuilder()
            .setBaseUrl("https://localhost:3000")
            .build(TestService);

service.getData()
        .then((data: string) => console.log(data))
        .catch((error: EchoError) => console.error(error))

More examples & documentation: Documentation

0.1.6

3 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2-a

4 years ago

0.0.1

4 years ago

0.0.2

4 years ago