Comments (4)
@Kelin2025 Tnx for suggestion. I will check your way.
from beauty-vuejs-boilerplate.
At first this boilerplate created for maximum transparent example how to structure vue.js projects.
Axios fortunately is great, well known and tested many users library. I think Axios doing a great job in my case.
I took a look at your services section. To be honest, it looks awful.
I wholly disagreed with yours opinion. Work with API in this project based on ES6 classes, and very flexible to next extension. Each api call can be modified to each case and encapsulated to one convenient interface. Using pure axios inside components, yes it really awful, but not as class based services.
you don't need to write tons of boilerplate code.
Unfortunately, we're not going anywhere.
And yes i will look at Apicase more closely when I have time.
from beauty-vuejs-boilerplate.
No-no-no-no-no, you didn't understand why I called it awful.
Using pure axios inside components, yes it really awful, but not as class based services.
I meant just this :)
If you want to use just requests, of course, there are no difference between Apicase and axios
BUT! Axios doesn't have flexible and scalable services. That's why you have services/auth.js
with a hand-made classes and tons of boilerplate.
Simple example of auth service:
/* Auth service */
const AuthService = new ApiService({
url: '/api/auth',
method: 'POST'
})
/* Save token on success auth */
AuthService.on('done', result => {
localStorage.setItem('token', result.body.token)
})
/* Calling service */
AuthService.doRequest({
body: { login: 'Hello', password: 'foobar' }
})
Example of services that depends on auth
/* Root services with auth check */
const Root = new ApiService(fetch, {
url: '/api',
hooks: {
/*
Check for auth and inject auth token.
If it fails, abort request with 401 error
*/
before ({ payload, meta, next }) {
const token = localStorage.getItem("token")
if (!token) {
if (meta.requiresAuth) {
fail({ status: 401 })
} else {
next(payload)
}
} else {
payload.headers = { ...payload.headers, Authorization: token }
next(payload)
}
}
}
})
/* Just array of services that will inherit Root hook and url */
const API = new ApiTree(Root, [
{
name: 'getPosts',
url: 'posts'
},
{
name: 'changeProfile',
url: 'profile/edit',
meta: { requiresAuth: true }
}
])
And there are a lot of features which I can't explain in a single message. Just try it ;)
from beauty-vuejs-boilerplate.
I'll try it! Tnx
from beauty-vuejs-boilerplate.
Related Issues (14)
- Error: This relative module was not found: * ./SpinnerWave.vue HOT 2
- Remove listener on anonymous function ? HOT 1
- Use multiple layouts
- No needs double `data` HOT 2
- License HOT 1
- problem with requiring images dynamically HOT 1
- Failed to compile HOT 1
- Pré-teste-Ezops
- vuejs
- npm run build uglifyjs error HOT 5
- Server-side rendering? HOT 1
- Css files order on build HOT 1
- Is there backend example source? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beauty-vuejs-boilerplate.