uri

如何设计出优美的Web API?

余生长醉 提交于 2020-01-17 12:38:52
1. 概述 WEB API的应用场景非常丰富,例如:将已有系统的功能或数据开放给合作伙伴或生态圈;对外发布可嵌入到其他网页的微件;构建前后端分离的WEB应用;开发跨不同终端的移动应用;集成公司内部不同系统等等。在上述场景里,你可能是WEB API的使用者,也可能是设计者,但你知道如何评判WEB API的优劣吗? 2. 评判标准 我们可以从三个维度来评判一个WEB API的优劣: 易于使用:WEB API的用户是程序还是人?我觉得首先是人,然后是程序。为什么这么说呢?是否采用某个WEB API的决定是人做出的,一个好的WEB API必须符合人的审美,例如:简短易记、通俗易懂、便于输入等。从程序角度看,WEB API应该遵循行业规范,在调用时不需要做特殊化处理,有利于复用已有的代码或工具。 便于更改:一个WEB API发布上线之后,免不了要根据真实用户的反馈或者业务发展的需要做更新修改,这些更新修改必须尽量不影响用户。要么提供多版本支持,要么给用户提供切实可行的更新策略等等。 健壮稳定:对外公开的WEB API存在被***的风险,以及无法准确预估的访问量等,一个好的WEB API必须要有防注入、防篡改、防重放等安全机制,还要在访问量急剧上涨时避免服务被击穿。 做到了上述三个方面,我们才有底气将一个WEB API对外开放,接受公众的检验。好的WEB API不仅方便使用

Ribbon负载均衡原理学习记录

旧街凉风 提交于 2020-01-17 04:24:41
ribbon项目通过RestTemplate发起微服务请求,但是知道的都是知道RestTemplate是spring自带的 那么和ribbon有什么关系呢? 标识.png 我们找到了@LoadBalanced标注的负载均衡标识 点进去 loadbalanced.png @Retention(RetentionPolicy.RUNTIME) ps:这里标识指的是 当编译完成后 运行保留 在jvm中运行 可以被反射调用 注意上面的绿色注释LoadBalancerClient来配置它 打开LoadBalancerClient类 里面有三个方法 image.png 同时继承了ServiceInstanceChooser 类 字面意思 服务选择实例 public interface LoadBalancerClient extends ServiceInstanceChooser { /** * execute request using a ServiceInstance from the LoadBalancer for the specified * service * @param serviceId the service id to look up the LoadBalancer * @param request allows implementations to

网络世界中的URI和URL

↘锁芯ラ 提交于 2020-01-17 00:58:21
有意思 有意思 今天我们来看看URI和URL到底是啥关系,是父子还是仇人? hhhh进入正题 URI ,也就是 统一资源标识符(Uniform Resource Identifier) 。因为它经常出现在浏览器的地址栏里,所以俗称为“网络地址”,简称“网址”, URI包含有 URL 和 URN 两个部分。 URI 主要有三个基本的部分构成: http://nginx.org/en/download.html 1.协议名:即访问该资源应当使用的协议,在这里是“http”; 2.主机名:即互联网上主机的标记,可以是域名或 IP 地址,在这里是“nginx.org”; 3.路径:即资源在主机上的位置,使用“/”分隔多级目录,在这里是“/en/download.html”。 URL,统一资源定位符(Uniform Resource Locator), 是 URI 的子集,也就是说每个URL都是URI URN , 统一资源名称(Universal Resource Name)。 URN只命名资源而不指定如何定位资源,比如urn:isbn:0451450523指定了一本书的ISBN,可以唯一标识这本书,但是没有指定到哪里定位这本书,这就是URN。 目前的互联网中,URN用得非常少,所以几乎所有的URI都是URL,一般的网页链接我们既可以称为URL,也可以称为URI。 哈哈哈

Spring RESTful URL call passing parameters

允我心安 提交于 2020-01-16 18:25:18
问题 How do I make a URL call to the following method if the testId is 1211.ml:FA890987422 . Since there is a ':' in the testId, I try to make a request using URLEncoding (%3A for :) like this http://localhost:8080/test/1211.ml%3AFA890987422 When I use the above URL, I get testId as 1211 as opposed to 1211.ml:FA890987422 even though '.' does not require URL encoding. What am I doing wrong? Also, would there be any other way to pass this testId to this method if I want to skip URL encoding?

Android FileProvider介绍

纵饮孤独 提交于 2020-01-16 15:55:42
Android 7.0 文件共享要使用FileProvider 对于面向Android 7.0的应用,Android框架执行的StrictMode API政策禁止在您的应用外部公开 file://URI 。如果一项包含文件URI的intent离开您的应用,则应用出现故障,并出现 FileUriExposedException 异常。 对于文件访问在Android 7.0以前可以使用file://uri的方式访问,但是这个地方有个问题,就是即使不是你自身应用产生的文件,只要知道对方的uri则就可以调用到,这样在安全性上就产生了风险。所以Android 7.0后新增了对文件跨进程访问的限制,这个限制会造成,如果使用file://uri的方式访问,则会出现android.os.FileUriExposedException的异常。 FileProvider简介 FileProvider是ContentProvider的一个特殊的子类,它让应用间共享文件变得更加容易,其通过创建一个Content URI来代替File URI。 一个Content URI 允许开发者可赋予一个临时的读或写权限。当创建一个包含Content URI的Intent的时候,为了能够让另一个应用也可以使用这个URI,你需要调用Intent.setFlags()来添加权限。只要接收Activity的栈是活跃的

安卓开发艺术探索一——Activity的生命周期和启动模式

人走茶凉 提交于 2020-01-16 13:24:49
文章目录 Activity的生命周期和启动模式 Activity的生命周期 正常情况下的生命周期 异常情况下的生命周期 1.系统配置改变导致活动被杀死并重新创建 2.资源内存不足导致低优先级的Activity被杀死 Activity的启动模式 启动模式的设置 IntentFilter的匹配规则 1.action的匹配规则 2.category的匹配规则 3.data的匹配规则 参考资料 Activity的生命周期和启动模式 Activity的生命周期 正常情况下的生命周期 onCreate:活动正在被创建。在此方法内可以做一些初始化工作 onReStart:活动正在重新启动。用户从其他活动回到当前活动时就会调用此方法。 onStart:活动正在被启动。此时活动已经可见,但未出现在前台,无法和用户交互 onResume:活动已经可见,并开始活动。(和onStart对比:两者都表示活动已经可见,onStart时活动还在后台,onResume时活动显示在前台) onPause:活动正在停止,正常情况下,onStop紧接着会被调用。此方法不能做耗时操作,否则会影响新活动的显示 onStop:活动即将停止,此方法不能做耗时操作 onDestroy:活动即将被销毁,可以做一些回收工作和资源释放 异常情况下的生命周期 1.系统配置改变导致活动被杀死并重新创建 如从竖屏切换到横屏时

Which parts of a URL need to be encoded?

旧时模样 提交于 2020-01-16 06:09:26
问题 With POST is easy and automatic: just use application/x-www-form-urlencoded or multipart/form-data or whatever. Instead, what parts should be encoded in a GET request? The whole query string? Just the parameter values but not the names ? And the fragment ? Maybe also the path ? But am pretty sure that I shouldn't encode the host or the scheme (since there are encoding and specs for international domains, like in japanese etc.). Hence the question is more about the URI 😉 Strangely I didn't

Java, “URI can't be null” error on simple HTTP client

℡╲_俬逩灬. 提交于 2020-01-16 05:37:07
问题 I'm trying to write a simple HTTP client that, given an absolute HTTP path, performs a simple HTTP GET request and prints out the content to standard output. However, I'm getting the following error on any page I try to load: java.lang.IllegalArgumentException: URI can't be null. at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:141) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:926) at sun.net.www.protocol.http.HttpURLConnection.connect

Unknown URL content:Unknown URL content:\com.mohit.provider.FormulaProvider\formulas

我只是一个虾纸丫 提交于 2020-01-16 04:48:07
问题 I get this error everytime I try to use my content provider to insert a URI. Here is the method: private void sample() { ContentValues values; values = new ContentValues(); values.put(Formulas.TITLE, "Formula1"); values.put(Formulas.FORMULA, "someformula"); getContentResolver().insert(getIntent().getData(), values); values = new ContentValues(); values.put(Formulas.TITLE, "Formula2"); values.put(Formulas.FORMULA, "someformula"); getContentResolver().insert(getIntent().getData(), values);

Uri.EscapeUriString - How do I use it?

随声附和 提交于 2020-01-16 00:23:41
问题 I am new to C# so i appreciate your help. I have the following code which calls an API. I need to have the URL values encoded. Now i have no idea how to do this. I would appreciate your assistance. Thank you. private void DeviceDetect_Load(object sender, EventArgs e) { var printerQuery = new ManagementObjectSearcher("Select * from Win32_Printer"); foreach (var printer in printerQuery.Get()) { var name = printer.GetPropertyValue("Name"); var status = printer.GetPropertyValue("Status"); var